2013-06-28 141 views

回答

2
UPDATE tblData SET Complete = GETDATE() WHERE transNo IN (SELECT transID from tblTrans WHERE transDesc = @TransDesc) 
0

嘗試......

UPDATE tblData SET Complete = GETDATE() 
    WHERE transNo IN (SELECT transID from tblTrans WHERE transDesc = @TransDesc); 
0
UPDATE tblData 
SET Complete = GETDATE() 
WHERE transNo IN 
    (SELECT transID 
    from tblTrans 
    WHERE transDesc = @TransDesc) 
2

這樣做有兩種方式。首先遵循原來的,並假定只有一個TRANSID:

DECLARE @transID int 

SELECT @transID = transID from tblTrans WHERE transDesc = @TransDesc 

UPDATE tblData SET Complete = GETDATE() WHERE transNo = @transID 

第二是整潔的,因爲它把整個更新成一個單一的命令:

UPDATE tblData SET Complete = GETDATE() 
    FROM tblTrans t 
    WHERE t.transID = tblData.transNo 
     AND t.transDesc = @TransDesc 
相關問題