简体   繁体   中英

SQL Server 2008 Proc fails in 2005

ALTER PROCEDURE [Lending].[uspHMDALarIncomeGet] (@ApplicationId int)
AS
BEGIN
    SET NOCOUNT ON
    SET TRANSACTION 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.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM