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 2008 Forums
 Transact-SQL (2008)
 conditional Where clause

Author  Topic 

gwjones12
Starting Member

9 Posts

Posted - 2011-04-04 : 12:23:02
I have a field that contains either a 'Y' or 'N' and a parameter coming into the SP with either 'Y' or NULL.

I need a WHERE clause that says "If the parameter passed in is 'Y' then select where the field = 'Y' else don't filter on this field at all (bring back all records)"

Thanks

jimf
Master Smack Fu Yak Hacker

2875 Posts

Posted - 2011-04-04 : 12:29:46
WHERE field = parameter or isnull(parameter,'') = ''


Jim

Everyday I learn something that somebody else already knew
Go to Top of Page

gwjones12
Starting Member

9 Posts

Posted - 2011-04-04 : 12:45:41
Works great, thanks
Go to Top of Page
   

- Advertisement -