更新数据时SQL Server出错

时间:2010-01-14 12:47:10

标签: sql-server

Create Table #tempTbl
(
 [AssID] [int],
 [dt] [datetime]
)

insert into #tempTbl 
select distinct(AssignmentID), (case when isdate(substring(NoteText,len('Vehicle picked-up was completed on')+1,len(NoteText)))=1 then
        substring(NoteText,len('Vehicle picked-up was completed on')+1,len(NoteText)) else '01/01/1900' end) as dop
from dbo.Assignment_Notes
where
    AssignmentID in(Select AssignmentID from dbo.Assignment_ClaimInfo 
        where InsuranceComp='Access General')
and
    AssignmentID in (Select AssignmentID from dbo.Assignment_BuyerInfo where PickupDate is null)
and
    NoteTypeID=5

update dbo.Assignment_BuyerInfo 
set PickupDate=#tempTbl.dt 
where AssignmentID=#tempTbl.AssID

1 个答案:

答案 0 :(得分:2)

将更新语句更改为以下内容:

update dbo.Assignment_BuyerInfo 
   set PickupDate=#tempTbl.dt 
  from dbo.Assignment_BuyerInfo, #tempTbl
 where AssignmentID=#tempTbl.AssID

您必须在from子句中包含额外的表,就像您在执行select语句时一样。