2012-01-04 50 views
1

如何在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,令牌出錯=其中]

我該如何解決?在此先感謝

+2

嘗試INSERT INTO ... SELECT ... WHERE(...) – 2012-01-04 02:05:09

+0

@ todda.speot.is:這是有效的語法,但最終會爲匹配查詢的表中的每一行重複插入操作。 – 2012-01-04 02:15:08

+0

@competent_tech除非SQL CE不同(我知道它在某些地方),但是'FROM'子句的省略可以避免這種情況。 – 2012-01-04 04:27:53

回答

2

您將不得不以舊式的方式做到這一點:從數據庫中選擇有問題的記錄,如果它不存在,請執行插入。

Here's a link到相關的MSDN文檔。