WHERE子句中的条件语句
问题描述:
我需要在我的where子句中写入一个条件语句,该条件语句根据传递给过程的参数使用不同的运算符。我似乎无法找到将工作的语法。WHERE子句中的条件语句
我的例子如下:
@DateValue datetime
select *
from table
where field1 = 'x'
and field2 = 'y'
and if @DateValue = '1/1/1900' then
field3 <= getdate()
else
field3 = @DateValue
end
感谢大家的帮助。
答
and ((@DateValue = '1/1/1900' and field3 <= getdate()) or
(@DateValue <> '1/1/1900' and [email protected]))
+0
完美运作。谢谢吉米! – Don 2009-08-03 22:30:03
什么是上下文?这条SQL语句在哪里存在? – 2009-08-03 22:38:30