all groups > sql server programming > april 2004 >
You're in the

sql server programming

group:

CASE Question


CASE Question mozHD
4/5/2004 8:46:03 PM
sql server programming:
Is it possible to do something like the example below? Is the syntax correct

CASE OrderMetho
WHEN 0 THEN 'Fax', 'Email
WHEN 1 THEN 'Telephone
EN

Re: CASE Question Aaron Bertrand [MVP]
4/5/2004 10:12:53 PM
If you're just returning for display, then just return one column. This is
a mere exercise in re-arranging your quotes.

CASE OrderMethod
WHEN 0 THEN 'Fax, Email'
WHEN 1 THEN 'Telephone'
END

Otherwise, David is right. A case expression can only return a single
value, not a list or variable number of values.

A




[quoted text, click to view]
moz

Re: CASE Question Kishor
4/6/2004 2:41:03 AM
Hi
I am asking basic question related to case of TSQL

can I replace multiple if statement with the case statement

if yes then how
TIA
Re: CASE Question David Portas
4/6/2004 5:23:02 AM
CASE must return a single expression not a value list. Something like this
should do what you want, assuming that Fax and Telephone are columns of
compatible datatypes.

....
ORDER BY
CASE @ordermethod
WHEN 0 THEN fax
WHEN 1 THEN telephone
END, email

--
David Portas
SQL Server MVP
--

Re: CASE Question Aaron Bertrand [MVP]
4/6/2004 7:41:17 AM
If you show how you're using IF now, we can probably show you how to use
CASE instead...



[quoted text, click to view]

Re: CASE Question Hugo Kornelis
4/6/2004 11:58:54 AM
[quoted text, click to view]

No. IF is a flow-control statement; CASE is an expression. They are
completely different things.

Check Books Online for a good explanation and some great examples of
both IF ... ELSE and CASE.

Best, Hugo
--

AddThis Social Bookmark Button