我已经编写了一个SQL Server存储过程。当我调试它时,它运行良好,但是当我从.net代码中调用存储过程时,它总是返回0。
请参考下面显示的代码。我的@REPAYFCIND
参数似乎有值,但似乎没有设置。
RepaymentStartegyIndicator
在我的数据库中的值为1,因此理想情况下,@REPAYFCIND
应该设置为1,这应该将FCLINDICATOR
更新为1;但是当我从代码执行存储过程时,我总是将FCLINDICATOR
设为0。
我尝试了一个内部查询,并使用变量将查询分开,并将结果放入其中,如下所示。但是,FCLINDICATOR
仅在调试存储过程时才返回1,但是从.NET代码执行时,它返回0。
SQL Server存储过程:
ALTER PROCEDURE [dbo].[USP_UPDATEFCLINDICATORNEW]
@pApplicationNumber NVARCHAR(12),
@pApplicationFactFindNumber NUMERIC(5,0)
AS
BEGIN
DECLARE @FCLINDICATORUPDATED TINYINT
SET @FCLINDICATORUPDATED = 0;
DECLARE @PRIMERESIDENTIALCURRENCY NVARCHAR(12)
SET @PRIMERESIDENTIALCURRENCY = (SELECT PRIMERESIDENTIALCURRENCY
FROM APPLICATIONFOREIGNCURRENCY
WHERE APPLICATIONNUMBER = @pApplicationNumber)
IF(@PRIMERESIDENTIALCURRENCY IS NOT NULL)
BEGIN
UPDATE APPLICATIONFACTFIND
SET FCLINDICATOR = 1
WHERE APPLICATIONNUMBER = @pApplicationNumber
AND APPLICATIONFACTFINDNUMBER = @pApplicationFactFindNumber
SET @FCLINDICATORUPDATED = 1
END
ELSE IF(@FCLINDICATORUPDATED = 0)
BEGIN
DECLARE @FOREIGNINCOMEINDICATOR NUMERIC
SET @FOREIGNINCOMEINDICATOR = (SELECT FOREIGNINCOMEIND
FROM APPLICATIONFOREIGNCURRENCY
WHERE APPLICATIONNUMBER = @pApplicationNumber)
IF(@FOREIGNINCOMEINDICATOR IS NOT NULL AND @FOREIGNINCOMEINDICATOR = 1)
BEGIN
UPDATE APPLICATIONFACTFIND
SET FCLINDICATOR = 1
WHERE APPLICATIONNUMBER=@pApplicationNumber
AND APPLICATIONFACTFINDNUMBER = @pApplicationFactFindNumber
SET @FCLINDICATORUPDATED = 1
END
ELSE IF(@FCLINDICATORUPDATED = 0)
BEGIN
DECLARE @REPAYFCIND TINYINT
DECLARE @MORTSUBQNUM NUMERIC
SELECT @MORTSUBQNUM = ACTIVEQUOTENUMBER
FROM APPLICATIONFACTFIND
WHERE APPLICATIONNUMBER= @pApplicationNumber
AND APPLICATIONFACTFINDNUMBER = @pApplicationFactFindNumber
SELECT @REPAYFCIND = REPAYMENTSTRATEGYFOREIGNCURRENCYIND
FROM LOANCOMPONENTFOREIGNCURRENCY
WHERE APPLICATIONNUMBER= @pApplicationNumber
AND MORTGAGESUBQUOTENUMBER = @MORTSUBQNUM
IF @REPAYFCIND = 1
BEGIN
UPDATE APPLICATIONFACTFIND
SET FCLINDICATOR = 1
WHERE APPLICATIONNUMBER = @pApplicationNumber
AND APPLICATIONFACTFINDNUMBER = @pApplicationFactFindNumber
SET @FCLINDICATORUPDATED = 1
END
ELSE IF(@FCLINDICATORUPDATED = 0)
BEGIN
UPDATE APPLICATIONFACTFIND
SET FCLINDICATOR = 0
WHERE APPLICATIONNUMBER = @pApplicationNumber
AND APPLICATIONFACTFINDNUMBER = @pApplicationFactFindNumber
END
END
END
END
我希望FCLINDICATOR
和@REPAYFCIND = 1
都应正确设置时将@REPAYFCIND
设置为1。