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 2005 Forums
 Transact-SQL (2005)
 case statement in where codition

Author  Topic 

jess1984
Starting Member

14 Posts

Posted - 2011-01-06 : 03:46:45

hai,
how to write query --case statement in where codition.
plz help

Thanks
Jess

jess1984

Lumbago
Norsk Yak Master

3271 Posts

Posted - 2011-01-06 : 04:05:25
[code]DECLARE @myVariable int = 3

SELECT *
FROM table
WHERE Column = CASE
WHEN @myVariable < 3 THEN 'Small'
WHEN @myVariable >= 3 AND < 10 THEN 'Medium'
ELSE 'Large'
END[/code]

- Lumbago

My blog (yes, I have a blog now! just not that much content yet)
-> www.thefirstsql.com
Go to Top of Page

madhivanan
Premature Yak Congratulator

22864 Posts

Posted - 2011-01-06 : 05:17:36
Change

DECLARE @myVariable int = 3

to

DECLARE @myVariable int
SET @myVariable = 3


Madhivanan

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

- Advertisement -