【发布时间】:2013-04-25 15:27:09
【问题描述】:
我正在尝试创建一个存储过程,它允许我更新 TripStop 表中的 ActualArrivalDate 和 ActualDepartureDate,其中 StopTypeCode = Drop 在 TripStopOrder 表中。
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 存储在临时变量中,然后在更新中使用它,例如select @v_tripstopid = tripstopid From dbo.TripStopOrder Join dbo.TripStop ON dbo.TripStopOrder.TripStopID = dbo.TripStop.TripStopID Where OrderID = ''and StopTypeCode ='Drop' 然后在更新中使用 Update dbo.TripStop SET ArrivalDate='' ,DepartureDate='' 其中 TripStopID = #v_tripstopid
标签: sql sql-server tsql sql-server-2008 stored-procedures