2010-01-14 54 views
0
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 
+0

請用合適的方式編寫代碼... – anishMarokey 2010-01-14 12:48:51

+1

請發佈您也收到的錯誤消息。 – Doogie 2010-01-14 12:51:05

+0

請編輯您的問題並添加一些有關確切問題的信息。您是否收到錯誤消息,或者INSERT或UPDATE無法正常工作? – DOK 2010-01-14 12:52:01

回答

2

改變你的更新語句如下:

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

你必須包括你的額外的表在FROM子句,就像你,如果你在做一個select語句。

+0

+1好抓! – 2010-01-14 13:58:04