如何在SQL Server ce中使用insert into ... where (..)
?SQL查詢在SQL Server精簡版中不起作用
這個查詢:
insert into table(field) values(@val)
where not exists (select field from table where field = @code);
回報
出現錯誤解析查詢。 [令牌行號= 1,令牌行偏移= 40,令牌出錯=其中]
我該如何解決?在此先感謝
如何在SQL Server ce中使用insert into ... where (..)
?SQL查詢在SQL Server精簡版中不起作用
這個查詢:
insert into table(field) values(@val)
where not exists (select field from table where field = @code);
回報
出現錯誤解析查詢。 [令牌行號= 1,令牌行偏移= 40,令牌出錯=其中]
我該如何解決?在此先感謝
您將不得不以舊式的方式做到這一點:從數據庫中選擇有問題的記錄,如果它不存在,請執行插入。
Here's a link到相關的MSDN文檔。
我很肯定你的問題是「不存在」,因爲SQL CE不支持。這裏有一個類似的問題,可能有所幫助的鏈接:「If not exists」 fails on SQL CE
嘗試INSERT INTO ... SELECT ... WHERE(...) – 2012-01-04 02:05:09
@ todda.speot.is:這是有效的語法,但最終會爲匹配查詢的表中的每一行重複插入操作。 – 2012-01-04 02:15:08
@competent_tech除非SQL CE不同(我知道它在某些地方),但是'FROM'子句的省略可以避免這種情況。 – 2012-01-04 04:27:53