SQL Server 2008 - Merge Script not working
-
26-10-2019 - |
문제
This merge script i'm writing isn't compiling and I believe I have the correct syntax.
MERGE into MyTable ct_current
USING (SELECT '0%' as Description, '0' as ShareAmount) ct_value
ON ct_current.ShareAmount = ct_value.ShareAmount
WHEN MATCHED THEN
UPDATE SET ct_current.Description = '0%'
WHEN NOT MATCHED THEN
INSERT (Description, ShareAmount)
VALUES (ct_value.Description, ct_value.ShareAmount);
GO
Error:
Msg 156, Level 15, State 1, Line 1 Incorrect syntax near the keyword 'into'. Msg 102, Level 15, State 1, Line 2 Incorrect syntax near 'ct_value'.
해결책 2
I realized that I had the SQL Server 2008 R2 client, but the server is SQL Server 2005.
다른 팁
Try
MERGE MyTable AS ct_current
USING (SELECT '0%' as Description, '0' as ShareAmount) ct_value
ON ct_current.ShareAmount = ct_value.ShareAmount
WHEN MATCHED THEN
UPDATE SET ct_current.Description = '0%'
WHEN NOT MATCHED THEN
INSERT (Description, ShareAmount)
VALUES (ct_value.Description, ct_value.ShareAmount);
제휴하지 않습니다 StackOverflow