0
感謝NLwino這個問題: Using output to set a variable in a merge statement設置一個值的變量在合併聲明
我要尋找從MERGE內返回我的新counter_的價值:
DECLARE @CounterType VARCHAR(50)
SET @CounterType = 'Case';
MERGE [dbo].[AN_Counter] WITH(ROWLOCK) TARGET
USING(SELECT @CounterType) SOURCE([KEY])
ON TARGET.[System_Name] = SOURCE.[KEY]
WHEN MATCHED THEN
UPDATE
SET COUNTER_ = COALESCE(COUNTER_,0) + 1
SELECT @CounterType = COALESCE(Prefix,'') + CAST(SUBSTRING('0000000000000000000000000000',1,padding - LEN(CAST (Counter_ AS VARCHAR))) + CAST (Counter_ AS VARCHAR) AS VARCHAR)
;
我會喜歡執行合併,並將新值置於@CounterType變量中,如上所述。
任何幫助,非常感謝。 中號