Results 1 to 2 of 2

Thread: Loop insert

  1. #1
    Join Date
    Jan 2005
    Posts
    30

    Unanswered: Loop insert

    Hi,

    I will do my best to explain my question:

    I have a field called CUSTOMER which contains a number such as C00001,
    C0002 etc.

    However i now have a new field called XCUSTOMER which is the new number that they relate to.

    CUSTOMER C00001 now relates to XCUSTOMER 493845.
    CUSTOMER C00002 now relates to XCUSTOMER 494343.

    Basically there are hundreds of these and i dont have the time to manually enter the data. I just want to say "where customer = C00001 then insert 49494 into XCUSTOMER and then loop through and insert them all.

    My table is called CUSTOMERINFO.

    If anyone could help it would be much apprieciated as it would save me so much time.

    Thanks

  2. #2
    Join Date
    Apr 2002
    Location
    Toronto, Canada
    Posts
    20,002
    Code:
    update customerinfo
       set xcustomer = case customer
                                when 'c00001' then 493845
                                when 'c00001' then 494343
                                ...
                             end
    rudy.ca | @rudydotca
    Buy my SitePoint book: Simply SQL

Posting Permissions

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