![](/img/trans.png)
[英]How to create a function which return a boolean depending on a select statement result
[英]How to create a CASE statement depending on the result of a Select Statement with parameter?
使用SQL Server,如何根據帶有參數的Select語句的值創建CASE語句?
如果ID在表Products中不存在(NULL),則需要插入數據,如果存在,則需要更新數據。
我有以下CASE語句查詢,但語法錯誤:
Select CASE WHEN (select ID from Products where ProdID = @ProdID) = NULL
then
(INSERT INTO Table...)
Else
(Update Table...)
END as Prods
FROM Products
IF EXISTS( select ID from Products where ProdID = @ProdID )
BEGIN
(Update Table...)
END
ELSE
(INSERT INTO Table...)
對於SQL Server 2008 +版本,請參閱MERGE語句
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.