所以我将insert语句转换为update语句。
这里是插入
insert into Matches(
SourceID,
SourceUniqueID,
ExtractionNumber,
ItemID,
MatchDate,
MatchBy,
MatchMethod)
select
m.SourceID
,m.SourceUniqueID
,m.ExtractionNumber
,m.ExtractionNumber
,getdate()
,replace( suser_sname(),'Bob\','')
,'EMTransmittalnumber'
from MatchData as m
where m.SourceID = 19
这是我到目前为止的更新声明,但它正在生成错误
update m2 set
m2.SourceID = m.SourceID
, m2.SourceUniqueID = m.SourceUniqueID
, m2.ExtractionNumber = m.ExtractionNumber
, m2.ItemID = m.ExtractionNumber
, m2.MatchDate = getdate()
, m2.MatchBy = replace( suser_sname(),'Bob\','')
, m2.MatchMethod = 'EMTransmittalnumber'
from MatchData as m
inner join Matches as m2
m2.itemid = m.extractionnumber
where m.sourceid = 19
错误说'm2'附近的语法不正确
任何想法?
答案 0 :(得分:2)
是的,您忘记了内部联接的“开启”:
update m2 set
m2.SourceID = m.SourceID
, m2.SourceUniqueID = m.SourceUniqueID
, m2.ExtractionNumber = m.ExtractionNumber
, m2.ItemID = m.ExtractionNumber
, m2.MatchDate = getdate()
, m2.MatchBy = replace( suser_sname(),'Bob\','')
, m2.MatchMethod = 'EMTransmittalnumber'
from MatchData as m
inner join Matches as m2 on
m2.itemid = m.extractionnumber
where m.sourceid = 19