0

我正在编写的这个合并脚本没有编译,我相信我有正确的语法。

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

错误:

消息 156,级别 15,状态 1,第 1 行关键字“into”附近的语法不正确。消息 102,级别 15,状态 1,第 2 行 'ct_value' 附近的语法不正确。

4

2 回答 2

1

尝试

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);
于 2011-01-27T20:34:21.590 回答
0

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

于 2011-01-27T21:39:13.353 回答