1. No Profile Picture
    Junior Member
    Devshed Newbie (0 - 499 posts)

    Join Date
    Dec 2003
    Rep Power

    Question return value from 3 fields into 1 field

    I would like to be able to query a table which contains 3 fields with identical information and return the value from any of those fields based on a pecking order. The pecking order would be like this: field a, field b, field c. If field a contains data, the returned value would be the value of field a even if fields b & c contain data
    since field a is highest in the pecking order. If field a contains no data, then the value of field b would be returned. The last check would be to return the data in field c if none was found in either a or b. Since I am lazy, I am looking for the simplest solution.

    Thanks in advance for any help you can give me.
  2. #2
  3. SQL Consultant
    Devshed Supreme Being (6500+ posts)

    Join Date
    Feb 2003
    Toronto Canada
    Rep Power
    assuming that "If field a contains no data" means null, this is the simplest solution:

    select coalesce(fielda,fieldb,fieldc) from yourtable


IMN logo majestic logo threadwatch logo seochat tools logo