Reputation: 983
I have a Procedure which returns MobileAreaCode+Mobile if they are not null I just want to add to it support for empty strings as well I tried(without the handle for empty string it works)
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
which doesn't work and results the following error:
Incorrect syntax near the keyword 'FROM'.
Upvotes: 0
Views: 3222
Reputation: 139010
You can use Use NULLIF (Transact-SQL).
select nullif(MobileAreaCode, '')+nullif(Mobile, '') as MobileAreaCodeMobile
from YourTable
Upvotes: 1
Reputation: 4622
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
Upvotes: 0