August 31, 2009 at 3:09 am
Hi,
Can somebody help me how to convert this to sql server query using CASE stmt?
,DECODE(c1.name, NULL, NULL, DECODE(c1.first_name, NULL, c1.name, c1.name || ', ' || c1.first_name))
August 31, 2009 at 3:33 am
Something like this?
CASE WHEN c1.name IS NULL THEN NULL
ELSE CASE WHEN c1.first_name IS NULL THEN c1.name
ELSE c1.name + ', ' + c1.first_name END
END
____________________________________________________
Deja View - The strange feeling that somewhere, sometime you've optimised this query before
How to get the best help on a forum
http://www.sqlservercentral.com/articles/Best+Practices/61537August 31, 2009 at 3:54 am
Thank u so much Mark!!
one doubt..Will CASE work the same as DECODE in case of nulls or should we add like
CASE WHEN c1.name IS NULL THEN NULL
ELSE CASE WHEN c1.first_name IS NULL THEN c1.name
ELSE isnull(c1.name,'') + ', ' + isnull(c1.first_name,'') END
END
August 31, 2009 at 4:02 am
rekha_sara (8/31/2009)
Thank u so much Mark!!one doubt..Will CASE work the same as DECODE in case of nulls or should we add like
CASE WHEN c1.name IS NULL THEN NULL
ELSE CASE WHEN c1.first_name IS NULL THEN c1.name
ELSE isnull(c1.name,'') + ', ' + isnull(c1.first_name,'') END
END
You won't need the ISNULLs (although they are not harmful), you will only get to that part of the CASE expression if both c1.name and c1.first_name are non-NULL.
____________________________________________________
Deja View - The strange feeling that somewhere, sometime you've optimised this query before
How to get the best help on a forum
http://www.sqlservercentral.com/articles/Best+Practices/61537September 1, 2009 at 1:44 am
Viewing 5 posts - 1 through 4 (of 4 total)
You must be logged in to reply to this topic. Login to reply