2012-05-17 18 views
1

我需要幫忙寫一些SQL。我不想問這樣一個菜鳥問題,但是下面的SQL查詢有什麼問題?我的SQL CASE語法有什麼問題?

select (case when mydate < '2010-1-1' Then '2000-1-1' ELSE mydate) from mytable; 

的想法是,我想從mytable得到mydate,但如果日期是2010年1月1日前,我希望語句返回2000年1月1日來代替。

回答

4

你之後指明MyDate 選擇(的情況下缺少end

case when mydate < '2010-1-1' Then '2000-1-1' ELSE mydate END 
+0

dasblinkenlight你打敗了我吧。 –

+0

@ChristopherKelly那麼,標題中的「syntax」這個詞的大多數問題都是這樣:) – dasblinkenlight

3

你最後錯過了end

select (case when mydate < '2010-1-1' Then '2000-1-1' ELSE mydate end) from mytable;

1

你缺少結束的時候指明MyDate < '2010-1-1',然後 '2000-1-1' ELSE mydate end)from mytable;