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
 SQL Server 2000 Forums
 Transact-SQL (2000)
 select in case function

Author  Topic 

dass05555
Yak Posting Veteran

55 Posts

Posted - 2008-04-22 : 12:24:19
dear guru's

how to write a select statement in a 'case' function

thanks 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 = @b
select case when x=y then (select max(s) from tbl) else t end
from 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.
Go to Top of Page

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.

- Jeff
http://weblogs.sqlteam.com/JeffS
Go to Top of Page

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 = @b
select case when x=y then (select max(s) from tbl) else t end
from 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



Madhivanan

Failing to plan is Planning to fail
Go to Top of Page

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.
Go to Top of Page

jsmith8858
Dr. Cross Join

7423 Posts

Posted - 2008-04-23 : 08:21:21
That's why I go with "case expression".

- Jeff
http://weblogs.sqlteam.com/JeffS
Go to Top of Page

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 CUSTOMERID
end
FROM Orders

chandan Joshi
Go to Top of Page
   

- Advertisement -