如何在Microsoft SQL Server Management Studio 2008 r2中將合併函數與@variables結合使用?帶變量的SQL MERGE
我在線搜索的所有示例都使用表格合併到表格中。這是可能的變量?
例如:
CREATE PROCEDURE UpdateOrder
@id int,
@payment_date smalldatetime,
@amount numeric(10,2)
AS
BEGIN
-- SET NOCOUNT ON added to prevent extra result sets from
-- interfering with SELECT statements.
SET NOCOUNT ON;
MERGE order AS o
USING @id, @payment_date, @amount
ON @id = o.id
WHEN MATCHED THEN
UPDATE SET
o.payment_date = @payment_date,
o.amount = @amount
o.last_updated_on = GETDATE()
WHEN NOT MATCHED THEN
INSERT(o.id,o.payment_id,o.amount)
VALUES(@id,@payment_id,@amount);
這是行不通的。謝謝!
你有沒有嘗試過類似'使用(選擇@id作爲id,@ payment_date作爲payment_date,@amount作爲金額)myVals'?然後引用myVals.id,ect?我沒有嘗試過,只是扔在那裏。 – Dan