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
 General SQL Server Forums
 New to SQL Server Programming
 using case in where condition

Author  Topic 

svibuk
Yak Posting Veteran

62 Posts

Posted - 2013-09-28 : 01:44:34
i have a SP with where condition
as where id=@id and month=@month and Eid=@Eid
wht i need is if @Eid=0 i need to display all the reocrds
if Eid>0 then display only that particular reocrd
i tried

where id=@id and month=@month and Eid=
case when @Eid=0 then Eid>0
else
Eid=@Eid
End
but its giving me error
Incorrect syntax near '>'.

visakh16
Very Important crosS Applying yaK Herder

52326 Posts

Posted - 2013-09-28 : 03:10:30
[code]
where (id=@id and month=@month and Eid=@Eid)
OR @Eid=0
[/code]

------------------------------------------------------------------------------------------------------
SQL Server MVP
http://visakhm.blogspot.com/
https://www.facebook.com/VmBlogs
Go to Top of Page

svibuk
Yak Posting Veteran

62 Posts

Posted - 2013-09-28 : 03:27:12
quote:
Originally posted by visakh16


where (id=@id and month=@month and Eid=@Eid)
OR @Eid=0


i dont have any record with eid =0
if eid =0 the i need to display all the records that where eid<>0 or eid>0
------------------------------------------------------------------------------------------------------
SQL Server MVP
http://visakhm.blogspot.com/
https://www.facebook.com/VmBlogs


Go to Top of Page

visakh16
Very Important crosS Applying yaK Herder

52326 Posts

Posted - 2013-09-28 : 03:38:06
quote:
Originally posted by svibuk

quote:
Originally posted by visakh16


where (id=@id and month=@month and Eid=@Eid)
OR @Eid=0


i dont have any record with eid =0
if eid =0 the i need to display all the records that where eid<>0 or eid>0
------------------------------------------------------------------------------------------------------
SQL Server MVP
http://visakhm.blogspot.com/
https://www.facebook.com/VmBlogs





Thats exactly what i've done
please try it first

its @Eid = 0 ie parameter = 0 not the field value Eid

------------------------------------------------------------------------------------------------------
SQL Server MVP
http://visakhm.blogspot.com/
https://www.facebook.com/VmBlogs
Go to Top of Page
   

- Advertisement -