SQL Server存储过程可以从Mgmt Studio执行,但不能从网站执行

时间:2013-07-09 18:19:10

标签: sql sql-server stored-procedures

我实际上有两个问题。下面的“Update O”从SQL Server Management Studio(2005)执行得很好,但是从网站(C#/ ASP.NET)执行时不会运行。我从原始工作代码中唯一的区别是将LEFT命令添加到LEFT(EmployeeBirthdate,4)

这很奇怪,因为第一个查询在网站上运行时运行正常,但第二个查询却没有。

ALTER PROCEDURE [dbo].[ValidateTransfers]
AS
BEGIN
    UPDATE p
    SET DATAREVISIONTYPE = 'Transfer'
    FROM abc as p
    WHERE DATAREVISIONTYPE  = 'Delete' AND
    (SELECT COUNT([OriginalUserId]) FROM abc WHERE DataRevisionType = 'Add' AND FirstName = p.FirstName 
    AND LastName = p.LastName AND EmployeeEmailAddress = p.EmployeeEmailAddress AND EmployeeBirthdate = LEFT(p.EmployeeBirthdate, 4))> 0

    UPDATE O
    SET DATAREVISIONTYPE = 'Modify' FROM abc as O
    WHERE DATAREVISIONTYPE = 'Add' AND
    (SELECT COUNT([OriginalUserId]) FROM abc WHERE DataRevisionType = 'Transfer' AND FirstName = O.FirstName 
    AND LastName = O.LastName AND EmployeeEmailAddress = O.EmployeeEmailAddress AND LEFT(EmployeeBirthdate, 4) = O.EmployeeBirthdate)> 0
END

我的第二个问题是,当我向set命令添加更多集合时,它们实际上并没有更改任何数据。

UPDATE O
SET DATAREVISIONTYPE = 'Modify' 
    O.OriginalUserID = OriginalUserID, 
    O.EmployeeBirthdate = EmployeeBirthdate, 
    O.User_ID = User_ID
FROM abc as O
WHERE DATAREVISIONTYPE = 'Add' AND
(SELECT COUNT([OriginalUserId]) FROM abc WHERE DataRevisionType = 'Transfer' AND FirstName = O.FirstName 
AND LastName = O.LastName AND EmployeeEmailAddress = O.EmployeeEmailAddress AND LEFT(EmployeeBirthdate, 4) = O.EmployeeBirthdate)> 0

提前致谢!

编辑:“修改”背后的逗号来自糟糕的工作副本粘贴。遗憾的是,这不是问题所在。

编辑2:此外,当我单独执行特定查询时,第二个需要大约一分钟才能完成,第一个是静止的。另一方面,如果我突出显示整个存储过程并点击执行,它会立即完成,并且具有与从网站上运行时相同的问题。 IE,正确的记录设置为“转移”但“修改”不起作用

1 个答案:

答案 0 :(得分:0)

“FROM:”之前还有一个额外的逗号

UPDATE O
SET DATAREVISIONTYPE = 'Modify', FROM abc as O