2009-08-03 11 views
0

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 

感謝を次のように

私の例があります。

+0

コンテキストとは何ですか?このSQLステートメントはどこにありますか? –

答えて

9
and ((@DateValue = '1/1/1900' and field3 <= getdate()) or 
    (@DateValue <> '1/1/1900' and [email protected])) 
+0

これは完全に機能しました。ありがとうジミー! – Don