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.
Author |
Topic |
dass05555
Yak Posting Veteran
55 Posts |
Posted - 2008-04-22 : 12:24:19
|
dear guru'show to write a select statement in a 'case' functionthanks in advance, |
|
nr
SQLTeam MVY
12543 Posts |
Posted - 2008-04-22 : 12:54:27
|
It's a statement not a function.You can control flow via an if statement or use a case statement in a select to return a value.This is a select in a case statement but I doubt if it's what you are wanting.if @a = @bselect case when x=y then (select max(s) from tbl) else t endfrom tbl==========================================Cursors are useful if you don't know sql.DTS can be used in a similar way.Beer is not cold and it isn't fizzy. |
|
|
jsmith8858
Dr. Cross Join
7423 Posts |
Posted - 2008-04-22 : 13:42:14
|
quote: Originally posted by nr It's a statement not a function.
It's actually much closer to a function than a statement. It's really an expression; it returns a value by evaluating expressions, it doesn't execute code.- Jeffhttp://weblogs.sqlteam.com/JeffS |
|
|
madhivanan
Premature Yak Congratulator
22864 Posts |
Posted - 2008-04-23 : 02:38:59
|
quote: Originally posted by nr It's a statement not a function.You can control flow via an if statement or use a case statement in a select to return a value.This is a select in a case statement but I doubt if it's what you are wanting.if @a = @bselect case when x=y then (select max(s) from tbl) else t endfrom tbl==========================================Cursors are useful if you don't know sql.DTS can be used in a similar way.Beer is not cold and it isn't fizzy.
But BOL says it is a function Simple CASE function:CASE input_expression WHEN when_expression THEN result_expression [ ...n ] [ ELSE else_result_expression ] END Searched CASE function:CASE WHEN Boolean_expression THEN result_expression [ ...n ] [ ELSE else_result_expression ] END MadhivananFailing to plan is Planning to fail |
|
|
nr
SQLTeam MVY
12543 Posts |
Posted - 2008-04-23 : 07:49:32
|
I sit corrected.Probably find it difficult to say "case function" though.==========================================Cursors are useful if you don't know sql.DTS can be used in a similar way.Beer is not cold and it isn't fizzy. |
|
|
jsmith8858
Dr. Cross Join
7423 Posts |
|
chandan_joshi80
Starting Member
30 Posts |
Posted - 2008-04-23 : 08:37:42
|
SELECT ORDERID,CASE WHEN CUSTOMERID LIKE 'A%' THEN (SELECT 'HELLOW FRIEND '+CUSTOMERID) ELSE CUSTOMERIDend FROM Orderschandan Joshi |
|
|
|
|
|