SQL Server 2008 Proc fails in 2005
ALTER PROCEDURE [Lending].[uspHMDALarIncomeGet] (@ApplicationId int)
AS
BEGIN
SET NOCOUNT ON
SET TR开发者_C百科ANSACTION ISOLATION LEVEL READ UNCOMMITTED
-- Total Income Data
DECLARE @ApplicantId int = (SELECT AT.ApplicantId FROM Lending.Applicant AT WHERE AT.ApplicationId = @ApplicationId)
SELECT
I.Amount
FROM Lending.Income I WHERE I.ApplicantId = @ApplicantId
END
Do you guys know how this proc can be written to succeed in 05?
-Scott
SQL2005 does not have the syntax to declare and assign a variable in the same statement. You would need to change
DECLARE @ApplicantId int = (SELECT ...
To
DECLARE @ApplicantId int
SELECT @ApplicantId = AT.ApplicantId
FROM Lending.Applicant AT
WHERE AT.ApplicationId = @ApplicationId
Edit:
It's just occurred to me that I might have changed the semantics a bit there if there can ever be more than one row matching AT.ApplicationId = @ApplicationId
.
DECLARE @ApplicantId int
SET @ApplicantId = (SELECT AT.ApplicantId ...
Would retain the original semantics and cause an error in that event.
精彩评论