Results 1 to 4 of 4
  1. #1
    Join Date
    Aug 2004
    Posts
    2

    Unanswered: Similar to COALESCE function

    I have three fields in a table say [F1, F2 & F3]. I need to fetch anyone of these three fields which has the maximum value between them.

    In Simple words i'm looking for some function which is similar to COALESCE function which returns the first NOT NULL value of the fields that were passed as arguments.

    FYI I'm using SQL Server 7.0 which does not supports UDF's

    Earlier response appreciated

    Thanks and Regards
    Chandru

  2. #2
    Join Date
    May 2004
    Posts
    125
    My first inpulse would be to use a case statement:

    select case when F1>f2 and f1 > f3 then F1
    when F2>f1 and f2 > f3 then F2
    when F3>f2 and f3 > f1 then F3
    from table


    HTH
    DMW

  3. #3
    Join Date
    Jun 2003
    Location
    Ohio
    Posts
    12,592
    Provided Answers: 1
    talk2cs, Your explanation is inconsistent.

    Do you want the field with the maximum value, or do you want the firt non-null value? Those are two different algorithms.
    If it's not practically useful, then it's practically useless.

    blindman
    www.chess.com: "sqlblindman"
    www.LobsterShot.blogspot.com

  4. #4
    Join Date
    Aug 2004
    Posts
    2
    Yeah DMWCincy solution fixed my problem, thanks a lot.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •