create procedure [dbo].[teststoredproc] (@startDate datetime, @endDate datetime) as
begin
set nocount on;
merge TargetTable with (tablockx) as target
using (
select
S.columnA, S.columnB
from
SourceTable S
where
S.ModifiedOn >= @startDate and S.ModifiedOn <= @enddate) as source
(columnA, columnB)
on (target.columnA= source.columnA)
when matched then update set
target.columnA = source.columnA, target.columnB = source.columnB
when not matched by target then insert
(columnA, columnB) values (source.columnA, source.columnB);
GO
当我尝试编译语句时出现以下错误:
';'附近的语法不正确。
在最后一行是:
(columnA, columnB) values (source.columnA, source.columnB);
答案 0 :(得分:1)
问题是你错过了一个END
when not matched by target then insert
(columnA, columnB) values (source.columnA, source.columnB);
END
GO