LOOP or IF/THEN ?

  • How can I modify the following so it will

    compare the 1stDate and 2ndDate fields,

    extracting the "most current date" ?

    ----------------------------------------

    SELECT     Email, 1stDate, 2ndDate

    FROM         orders

    ----------------------------------------

    Orders (table layout)

      Email, 1stDate, 2ndDate

        test@test.com, 20040105, 20050105

        john@doe.com, 20030403, 20020503

    ----------------------------------------

    Desired Result

      Email, CurrentDate

        test@test.com, 20050105

        john@doe.com, 20030403

  • Select

      Email,

      Case

        When 1stDate > 2ndDate Then 1stDate

        Else 2ndDate

      End  As MostCurrentDate

    From Orders

     

  • SELECT email, CASE WHEN firstd > lastd THEN firstd

    ELSE lastd

    END

    FROM @val

    Quand on parle du loup, on en voit la queue

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

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