我想創建一個存儲過程,這將允許我更新TripStopOrder表中StopTypeCode = DropStripStop表中的ActualArrivalDate和ActualDepartureDate。創建一個存儲過程
Create Proc spUpdateTable
@OrderID int, @ArrivalDate datetime, @DepartureDate datetime
As
Begin
Begin Transaction
Select * From dbo.TripStopOrder
Join dbo.TripStop ON dbo.TripStopOrder.TripStopID = dbo.TripStop.TripStopID
Where OrderID = ''and StopTypeCode ='Drop'
一旦我找到這條記錄,我需要抓住TripStopId並將它傳遞給Update語句。 不知道如何......我可以使用臨時表,然後運行另一個Select語句來獲取TripStopID?
Update dbo.TripStop SET ArrivalDate='',DepartureDate=''
Where TripStopID = ''
End
Commit
任何意見或建議將不勝感激。 〜新手〜
店TripStopId一個臨時變量,然後在更新例如使用選擇@v_tripstopid = tripstopid從dbo.TripStopOrder 加入dbo.TripStop ON dbo.TripStopOrder.TripStopID = dbo.TripStop.TripStopID Where OrderID =''和StopTypeCode ='Drop'然後在更新中使用更新dbo.TripStop SET ArrivalDate = '',DepartureDate ='' 其中TripStopID = #v_tripstopid – Satya 2013-04-25 15:30:27
[使用SQL Server中的JOIN更新表格]可能的重複(http://stackoverflow.com/questions/1604091/update-a-table-using-join -in-sql-server) – 2013-04-25 16:02:16