I've worked around this problem for a while but I figured there has to be an easier way to do it so I decided to make a post.
I've got a data filter parameter and I want to make a if/else branch or case branch in my where clause. If my @State variable is anything other than "All" I want to add the "And (state = @State)" to my where clause.
SELECT timestamp, service, state
FROM socketLog
WHERE (timestamp BETWEEN dbo.fxMilitaryTime('02/01/12', 'mdy')
AND DATEADD(dd, 1, getdate())) AND (state = @State)
ORDER BY service
I attempted to get a if/else and a case statement to work in the where but I had syntax issues. I'm pretty sure that case and if statements are supported in a where clause but I can't get it working right.
Thanks to those that have time to assist.