SQL Server Forums
Profile | Register | Active Topics | Members | Search | Forum FAQ
 
Register Now and get your question answered!
Username:
Password:
Save Password
Forgot your Password?

 All Forums
 General SQL Server Forums
 New to SQL Server Programming
 using case in where condition
 New Topic  Reply to Topic
 Printer Friendly
Author Previous Topic Topic Next Topic  

svibuk
Yak Posting Veteran

62 Posts

Posted - 09/28/2013 :  01:44:34  Show Profile  Reply with Quote
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

India
52323 Posts

Posted - 09/28/2013 :  03:10:30  Show Profile  Reply with Quote

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


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

svibuk
Yak Posting Veteran

62 Posts

Posted - 09/28/2013 :  03:27:12  Show Profile  Reply with Quote
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

India
52323 Posts

Posted - 09/28/2013 :  03:38:06  Show Profile  Reply with Quote
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
  Previous Topic Topic Next Topic  
 New Topic  Reply to Topic
 Printer Friendly
Jump To:
SQL Server Forums © 2000-2009 SQLTeam Publishing, LLC Go To Top Of Page
This page was generated in 0.06 seconds. Powered By: Snitz Forums 2000