views:

192

answers:

1

I need to write a conditional statement in my where clause that uses different operators based on the parameter passed into the procedure. I can't seem to find the syntax that will work.

My example is as follows:

@DateValue datetime

select * 
from table
where field1 = 'x'
and field2 = 'y'
and if @DateValue = '1/1/1900' then
  field3 <= getdate()
else
  field3 = @DateValue
end

Thanks for everyone's assistance.

+9  A: 
and ((@DateValue = '1/1/1900' and field3 <= getdate()) or 
     (@DateValue <> '1/1/1900' and field3=@DateValue))
Jimmy
That worked perfectly. Thanks Jimmy!
love2fly