0

我有一个过程,如果它们不为空,则返回 MobileAreaCode+Mobile 我只想添加对空字符串的支持以及我尝试过的(没有空字符串的句柄它可以工作)

ALTER PROCEDURE PROC_NAME
    @Identification INT
AS
BEGIN
    SELECT 
    CASE WHEN MobileAreaCode is NOT NULL OR Mobile is NOT NULL 
OR MobileAreaCode<>'' OR Mobile<>''
    THEN
        MobileAreaCode+Mobile
    END
    FROM 
        TABLE_NAME
    WHERE 
        id = 123456789
END
GO

这不起作用并导致以下错误:

关键字“FROM”附近的语法不正确。

4

2 回答 2

1

您可以使用 Use NULLIF (Transact-SQL)

select nullif(MobileAreaCode, '')+nullif(Mobile, '') as MobileAreaCodeMobile
from YourTable

SQL小提琴

于 2013-09-18T11:21:57.957 回答
0
ALTER PROCEDURE PROC_NAME
@Identification INT
AS
BEGIN
SELECT 
CASE WHEN (MobileAreaCode is NOT NULL) AND (Mobile is NOT NULL) 
AND (len(MobileAreaCode)>0) AND (len(Mobile)>0)
THEN
    MobileAreaCode+Mobile
END
FROM 
    TABLE_NAME
WHERE 
    id = 123456789
END
GO
于 2013-09-18T10:44:21.073 回答