如何找到修复SP的解决方案,当我从php运行时,我得到Error 102 severity 15 state 1
PHP:
$stmt = mssql_init('DBO.TEST_sp_SET_Claim Status');
mssql_bind($stmt, '@ClaimID', $claimID, SQLINT4);
mssql_bind($stmt, '@Status', $status, SQLINT4);
mssql_bind($stmt, '@UserID', $userID, SQLINT4);
$result = mssql_execute($stmt);
SP:
@ClaimID INT,
@Status INT,
@UserID INT
AS
BEGIN
SET NOCOUNT ON;
--Start : Update claim Status.
UPDATE DBO.Payment
SET StatusID = @Status,
ClosedBy = CASE
WHEN @Status = 2 THEN @UserID
WHEN @Status = 13 THEN @UserID
WHEN @Status = 14 THEN @UserID
WHEN @Status = 16 THEN @UserID
ELSE NULL
END ,
UserID = @UserID,
DateClosed = CASE
WHEN @Status = 2 THEN GETDATE()
WHEN @Status = 13 THEN GETDATE()
WHEN @Status = 14 THEN GETDATE()
WHEN @Status = 16 THEN GETDATE()
ELSE NULL
END
FROM DBO.ClaimHeader P_CH
INNER JOIN DBO.Payment P_PI ON P_CH.ClientClaimID = P_PI.ClientClaimID
WHERE P_CH.ClientClaimID = @ClaimID
--End
END
在SQL Server Profiler中我得到
Exception Error 102 severity 15 state 1
SQL:BatchStarting EXEC DBO.TEST_sp_SET_Claim Status @ClaimID=20,@Status=4,@UserID=22
SQL:BatchCompleted EXEC DBO.TEST_sp_SET_Claim Status @ClaimID=20,@Status=4,@UserID=22
当我直接在sql中运行时,它工作正常
DECLARE @return_value int
EXEC @return_value = [dbo].[TEST_sp_SET_Claim Status]
@ClaimID = 20,
@Status = 4,
@UserID = 22
SELECT 'Return Value' = @return_value
当我直接从php运行查询时,它的工作原理很像
$query="
DECLARE @Status INT, @UserID INT, @ClaimID INT
SET @Status=$status
SET @UserID = $userID
SET @ClaimID = $claimID
UPDATE DBO.Payment
SET StatusID = @Status,
ClosedBy = CASE
WHEN @Status = 2 THEN @UserID
WHEN @Status = 13 THEN @UserID
WHEN @Status = 14 THEN @UserID
WHEN @Status = 16 THEN @UserID
ELSE NULL
END ,
UserID = @UserID,
DateClosed = CASE
WHEN @Status = 2 THEN GETDATE()
WHEN @Status = 13 THEN GETDATE()
WHEN @Status = 14 THEN GETDATE()
WHEN @Status = 16 THEN GETDATE()
ELSE NULL
END
FROM DBO.ClaimHeader P_CH
INNER JOIN DBO.Payment P_PI ON P_CH.ClientClaimID = P_PI.ClientClaimID
WHERE P_CH.ClientClaimID = @ClaimID
";
$result=mssql_query($query);
我唯一能想到的是名称TEST_sp_SET_Claim Status
中的空格,但是这个Sp也被其他应用程序使用,它运行正常,我无法改变......可能是另一回事?
答案 0 :(得分:1)
问题是SP名称DBO.TEST_sp_SET_Claim Status
,状态之前有一个空格。
我修复了方括号[]
$stmt = mssql_init('[DBO].[TEST_sp_SET_Claim Status]');
建议使用方括号来避免这种问题。
如果列名或Sp名称包含空格或与保留字冲突