我正在尝试根据另一个表中的某个值是否为“999”来更新表。下面是代码。我正在跨数据库,所以我对语法有点困惑。
我收到此错误: SQL错误:关键字“left”附近的语法不正确。
declare @ProcessDate datetime
set @ProcessDate=getdate()
update ${BccrDatabase}..ReturnsHeader
left join ${JdeDatabase}.f47011 poh on --Temp Header
poh.SYEDOC = ReturnsHeader.DocumentNumber and poh.SYEDCT = 'EP'
left join ${JdeDatabase}.f4201 soh on --Prod Header
soh.SHKCOO = poh.SYEKCO
and soh.SHDOCO = poh.SYDOCO
and soh.SHDCTO = poh.SYEDCT
left join ${JdeDatabase}.f4211 sod on --Production Detail
sod.SDKCOO = soh.SHKCOO
and sod.SDDOCO = soh.SHDOCO
and sod.SDDCTO = soh.SHDCTO
left join jde_crp.crpdta.f42119 hist on --History Detail
hist.sddoco = soh.SHDOCO and
hist.sdkcoo = soh.SHKCOO and
hist.sddcto = soh.SHDCTO
set
SentToEdiDate=@ProcessDate
where
SentToEdiDate is null
and ApprovalStepID=4 -- Complete
and DocumentBranchPlant=@BranchPlant
and sod.SDNXTR is not null or hist.SDNXTR is not null
and sod.SDNXTR = '999' or hist.SDNXTR = '999'
答案 0 :(得分:2)
如果我理解正确,您的代码应该是:
declare @ProcessDate datetime
set @ProcessDate=getdate()
update ${BccrDatabase}..ReturnsHeader
set SentToEdiDate=@ProcessDate
FROM ${BccrDatabase}..ReturnsHeader
left join ${JdeDatabase}.f47011 poh on --Temp Header
poh.SYEDOC = ReturnsHeader.DocumentNumber and poh.SYEDCT = 'EP'
left join ${JdeDatabase}.f4201 soh on --Prod Header
soh.SHKCOO = poh.SYEKCO
and soh.SHDOCO = poh.SYDOCO
and soh.SHDCTO = poh.SYEDCT
left join ${JdeDatabase}.f4211 sod on --Production Detail
sod.SDKCOO = soh.SHKCOO
and sod.SDDOCO = soh.SHDOCO
and sod.SDDCTO = soh.SHDCTO
left join jde_crp.crpdta.f42119 hist on --History Detail
hist.sddoco = soh.SHDOCO and
hist.sdkcoo = soh.SHKCOO and
hist.sddcto = soh.SHDCTO
where
SentToEdiDate is null
and ApprovalStepID=4 -- Complete
and DocumentBranchPlant=@BranchPlant
and sod.SDNXTR is not null or hist.SDNXTR is not null
and sod.SDNXTR = '999' or hist.SDNXTR = '999'
一般结构是:
UPDATE a
SET a.YourColumn = newValue
FROM Table1 AS a
JOIN Table2 AS b
ON a.JoinColumn = b.JoinColumn
WHERE ...