Link to home
Start Free TrialLog in
Avatar of techques
techques

asked on

How to use case in MSSQL 2005?

Hi

I have a select query which needs to take clientid as where condition. However, if the clientid=0, then it needs to select all result.


Select * from client where type=1 and clientid=2
 
if clientid=0 which I pass it from C#
then
Select * from client where type=1  //and clientid=0 would be taken out
 
I tried:
Select * from client where type=1 
case when (t.clientid ='0' then '' when t.clientid <> '0' then and t.clientid = '2') order by [id] desc
 
But, it said Incorrect syntax near the keyword 'case'.

Open in new window

ASKER CERTIFIED SOLUTION
Avatar of Guy Hengel [angelIII / a3]
Guy Hengel [angelIII / a3]
Flag of Luxembourg image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of techques
techques

ASKER

Excellent!! Thanks