Newbie Question:If else Sql Question

  • In this case i am expecting the else statement to execute. please correct

    dECLARE @BusinessEntityId INT

    SET @BusinessEntityId=1003

    IF @BusinessEntityId<=(SELECT MAX(BusinessEntityId) AS BusinessEntityId FROM Person.Person)

    BEGIN

    SELECT * FROM Person.Person

    WHERE BusinessEntityID<=@BusinessEntityId

    END

    ELSE

    IF @BusinessEntityId>=1000 AND @BusinessEntityId<2000

    SELECT * FROM Person.Person

    WHERE BusinessEntityID>=@BusinessEntityId AND BusinessEntityID<=@BusinessEntityId

    • This topic was modified 2 years, 6 months ago by  praveensc2021.
  • Your final WHERE clause makes no sense:

    WHERE BusinessEntityID >= @BusinessEntityId AND BusinessEntityID <= @BusinessEntityId;

    This is equivalent to

    WHERE BusinessEntityID = @BusinessEntityId

    Is that what you meant?

    The absence of evidence is not evidence of absence
    - Martin Rees
    The absence of consumable DDL, sample data and desired results is, however, evidence of the absence of my response
    - Phil Parkin

  • Well what value does this return?

     

    (SELECT MAX(BusinessEntityId) AS BusinessEntityId FROM Person.Person)

Viewing 3 posts - 1 through 2 (of 2 total)

You must be logged in to reply to this topic. Login to reply