Please start any new threads on our new site at https://forums.sqlteam.com. We've got lots of great SQL Server experts to answer whatever question you can come up with.

 All Forums
 General SQL Server Forums
 New to SQL Server Programming
 case statement get values

Author  Topic 

tpiazza55
Posting Yak Master

162 Posts

Posted - 2007-01-08 : 08:43:33
i have a case statement

CASE
when stuff then value
end as email

there are several instances where i come up with 2 values

is there a way to get these values distinctly

not email = value1 + "," + value2

but actually get value1 and value2 so i can use them as output without parsing in the program?


SwePeso
Patron Saint of Lost Yaks

30421 Posts

Posted - 2007-01-08 : 08:45:30
Is this still this question http://www.sqlteam.com/forums/topic.asp?TOPIC_ID=77171?
Or this http://www.sqlteam.com/forums/topic.asp?TOPIC_ID=77184?


Peter Larsson
Helsingborg, Sweden
Go to Top of Page

tpiazza55
Posting Yak Master

162 Posts

Posted - 2007-01-08 : 08:55:58
no different one
Go to Top of Page

SwePeso
Patron Saint of Lost Yaks

30421 Posts

Posted - 2007-01-08 : 09:01:31
SELECT CASE WHEN Value1 IS NULL THEN ISNULL(Value2, '')
WHEN Value2 IS NULL THEN ISNULL(Value1, '')
ELSE Value1 + ', ' + Value2
END


Peter Larsson
Helsingborg, Sweden
Go to Top of Page

X002548
Not Just a Number

15586 Posts

Posted - 2007-01-08 : 09:19:40
What if there is no value?

COALESCE(Value1, Value2)




Brett

8-)

Hint: Want your questions answered fast? Follow the direction in this link
http://weblogs.sqlteam.com/brettk/archive/2005/05/25/5276.aspx

Add yourself!
http://www.frappr.com/sqlteam



Go to Top of Page

SwePeso
Patron Saint of Lost Yaks

30421 Posts

Posted - 2007-01-08 : 09:24:54
What do you mean?


Peter Larsson
Helsingborg, Sweden
Go to Top of Page

X002548
Not Just a Number

15586 Posts

Posted - 2007-01-08 : 09:49:10
quote:
Originally posted by Peso

What do you mean?


Peter Larsson
Helsingborg, Sweden



What do I mean? What if both values are null?



Brett

8-)

Hint: Want your questions answered fast? Follow the direction in this link
http://weblogs.sqlteam.com/brettk/archive/2005/05/25/5276.aspx

Add yourself!
http://www.frappr.com/sqlteam



Go to Top of Page

SwePeso
Patron Saint of Lost Yaks

30421 Posts

Posted - 2007-01-08 : 09:54:30
No, I meant with "No value".

If you refer to NULL value, and both parameters are NULL, my first CASE will handle that.

I wrote this way to make the output look nice, without unnecessary commas.


Peter Larsson
Helsingborg, Sweden
Go to Top of Page

SwePeso
Patron Saint of Lost Yaks

30421 Posts

Posted - 2007-01-08 : 10:02:06
But you are right if one or both of the parameters are empty.

SELECT CASE WHEN Value1 IS NULL OR Value1 = '' THEN ISNULL(Value2, '')
WHEN Value2 IS NULL OR Value2 = '' THEN ISNULL(Value1, '')
ELSE Value1 + ', ' + Value2
END


Peter Larsson
Helsingborg, Sweden
Go to Top of Page

tpiazza55
Posting Yak Master

162 Posts

Posted - 2007-01-08 : 12:16:21
thanks
Go to Top of Page
   

- Advertisement -