我想知道是否有人可以提供帮助。
我的存储过程中有这段代码,但Merge不适用于字段Address。适用于其他领域。
我有一个源文件,其中包含要填充到源的所有地址。
Source包含一个包含所有地址的字段。当我运行查询时,“目标地址”列仅填充具有正确地址的一行。我可以看到源中存在位置更改,为该行更新了具有地址的位置,但没有更新表中的其余属性。
DECLARE @SQLMerge nvarchar(4000)
SET @SQLMerge=' MERGE '+@RPTblName+' AS target'+
' USING '+@CMTblName+' AS source
ON target.VersionEndDate IS NULL AND target.PtyId = source.PtyId
WHEN MATCHED AND NOT (target.Location =source.Location AND target.Price=source.Price
AND target.PtyCode=source.PtyCode
AND target.[FloorSpace] = source.[FloorSpace]
AND target.Address = source.Address)
THEN UPDATE SET VersionEndDate ='''+CONVERT(NVARCHAR(50),@ReportMonthEND,121 )+''';'
IF @debug=1 print @SQLMerge
EXECUTE sp_executesql @SQLMerge
答案 0 :(得分:0)
试试这个:
DECLARE @SQLMerge nvarchar(4000)
SET @SQLMerge=' MERGE '+@RPTblName+' AS target'+
' USING '+@CMTblName+' AS source
ON target.VersionEndDate IS NULL AND target.PtyId=source.PtyId
WHEN MATCHED AND NOT (target.Location =source.Location AND target.Price=source.Price
AND target.PtyCode=source.PtyCode
AND target.[FloorSpace] = source.[FloorSpace]
AND target.Address = source.Address)
THEN UPDATE SET target.VersionEndDate ='''+CONVERT(NVARCHAR(50),@ReportMonthEND,121 )+''';'
IF @debug=1 print @SQLMerge
EXECUTE sp_executesql @SQLMerge