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

    Join Date
    Dec 2003
    Posts
    2
    Rep Power
    0

    Question Query one column to populate another


    I wonder if you can offer some assistance with this query.

    I need to query a table in SQL2000 to read the value in one column and populate a new column with new data. For example:

    If Column A = ABC in table Class_001 I need a query statement to populate Column Z with 123

    If Column A = XYZ in table Class_001 I need a query statement to populate Column Z with 789

    Your help would be much appreciated.
  2. #2
  3. SQL Consultant
    Devshed Supreme Being (6500+ posts)

    Join Date
    Feb 2003
    Location
    Toronto Canada
    Posts
    27,172
    Rep Power
    4274
    Code:
    update Class_001
       set Z = case when A = 'ABC' 
                    then 123 
                    else 789 end
     where A in ('ABC','XYZ')
    rudy
    http://r937.com/
  4. #3
  5. No Profile Picture
    Junior Member
    Devshed Newbie (0 - 499 posts)

    Join Date
    Dec 2003
    Posts
    2
    Rep Power
    0
    Many thanks for your quick reply.

    Your query works but I have changed it slightly as I would like to populate Test with different data depending on the data in PN

    This is my effort..... Is there an easier way?

    update Class_021
    set Test = '1' where PN = '3001'
    update Class_021
    set Test = '2' where PN = '3002'
    update Class_021
    set Test = '3' where PN = '3003'
  6. #4
  7. SQL Consultant
    Devshed Supreme Being (6500+ posts)

    Join Date
    Feb 2003
    Location
    Toronto Canada
    Posts
    27,172
    Rep Power
    4274
    heck no, that looks fine

IMN logo majestic logo threadwatch logo seochat tools logo