开发者

SQL Server 2008 - Merge Script not working

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开发者_Python百科'.


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);


I realized that I had the SQL Server 2008 R2 client, but the server is SQL Server 2005.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜