程序执行时不更新数据库

Procedure Not Updating DB When Executing

我有两个简单的更新语句,它们分别在 运行 时起作用。但我想将它们放在一个过程中,这样我就可以定义两个角色和每个角色的生效日期。

更新语句为:

UPDATE DTSMobileDetail
SET DTSMD.MobileID=294
FROM DTSMobileDetail DTSMD
Inner Join DTSDetail DTSD on DTSMD.ShiftID=DTSD.ShiftID
Inner Join LocationDetail LD on DTSD.LocationID=LD.LocationID
Inner Join Accounts Acct on LD.AccountID=Acct.AccountID
Inner Join CenterDetail CD on Acct.CenterID=CD.CenterID
Inner Join IDViewCollectionOp CO on CD.CenterID=CO.CodeID
WHERE CO.CodeID in ('108','110','106','107')
and DTSMD.MobileID=700

-- Update Futre Drives with new Staff Template
UPDATE DSMD
SET DSMD.MobileID=294
FROM DriveMaster DM
Inner Join DriveShiftDetail DSD on DM.DriveID=DSD.DriveID
Inner Join DriveShiftMobileDetail DSMD on DSD.ShiftID=DSMD.ShiftID
Inner Join CenterDetail CD on DM.CenterID=CD.CenterID
Inner Join IDViewCollectionOp CO on CD.CenterID=CO.CodeID
WHERE DSMD.MostRecent=1
And CO.CodeID in ('108','110','106','107')
And DSMD.MobileID=700
And DM.FromDateTime >= '02/19/2015'

我想要完成的是将新的移动 ID (@NewRoleName) 和旧的移动 ID (@OldRoleName) 设置为变量,并将第二次更新中的日期设置为 @EffectiveDate。

我已尝试将更新插入到过程中:

SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
--CREATE PROCEDURE CA66_Staff_Role_Change
Alter PROCEDURE CA66_Staff_Role_Change
-- Declare new role, old role, effective drive date variables
@OldRoleName int,
@NewRoleName int,
@EffectiveDate datetime
AS
BEGIN
SET NOCOUNT ON;

-- Update Accounts with new Staff Template
UPDATE DTSMD
SET DTSMD.MobileID=@NewRoleName
FROM DTSMobileDetail DTSMD
Inner Join DTSDetail DTSD on DTSMD.ShiftID=DTSD.ShiftID
Inner Join LocationDetail LD on DTSD.LocationID=LD.LocationID
Inner Join Accounts Acct on LD.AccountID=Acct.AccountID
Inner Join CenterDetail CD on Acct.CenterID=CD.CenterID
Inner Join IDViewCollectionOp CO on CD.CenterID=CO.CodeID
WHERE CO.CodeID in ('108','110','106','107')
and DTSMD.MobileID=@OldRoleName

-- Update Futre Drives with new Staff Template
UPDATE DSMD
SET DSMD.MobileID=@NewRoleName
FROM DriveMaster DM
Inner Join DriveShiftDetail DSD on DM.DriveID=DSD.DriveID
Inner Join DriveShiftMobileDetail DSMD on DSD.ShiftID=DSMD.ShiftID
Inner Join CenterDetail CD on DM.CenterID=CD.CenterID
Inner Join IDViewCollectionOp CO on CD.CenterID=CO.CodeID
WHERE DSMD.MostRecent=1
And CO.CodeID in ('108','110','106','107')
And DSMD.MobileID=@OldRoleName
And DM.FromDateTime >= @EffectiveDate

END
GO

当我尝试执行语句时:

Exec CA66_Staff_Role_Change 294,700,'02/19/2015'
Go

说执行成功了,但是我查看记录,什么都没有更新。

对我可能遗漏的内容有什么建议吗?

谢谢,

您实际上在原始更新语句中将 294 传递给 @oldRoleName,294 应该是新的角色名称

所以正确传递值

Exec CA66_Staff_Role_Change 700,294,'02/19/2015'