Solved

Replace string value to correspond with ID value

Posted on 2008-10-31
2
354 Views
Last Modified: 2011-09-20
I'm in the process of converting an old database to a new SQL 2005 database.  The table I'm having trouble with is similar to this:

OrderDate           VendorName            Comments
-------------------------------------------------------------------
10/2/2008           Some Company        Great comment.
9/30/2001           ABC Industries         More comments.
11/18/2004         Big Company            Terrible comment.


My goal is to create another table (called "Vendors") that contains all the different vendor names and gives each a unique ID:

VendorID           Name
---------------------------------------------
1                        Some Company
2                        ABC Industries
3                        Big Company


I already have the new "Vendors" table populated with the vendor names, but I'm not sure how to then go back to the original table and replace the "VendorName" values with the new VendorID.  I know how to script something to perform this (in VB or PHP or something), but I'd like to do this with SQL.

Thanks in advance for any help, and let me know if you need clarification.
0
Comment
Question by:wotech
2 Comments
 
LVL 4

Accepted Solution

by:
justin-clarke earned 500 total points
Comment Utility
UPDATE tblOLD

SET tblOLD.VendorName = tblNEW.VendorID

FROM tblOLD INNER JOIN
 tblNew ON tblNEW.Name = tblOLD.VendorName

WHERE (tblNEW.Name = tblOLD.VendorName)


Possibly something like that from the top of my head.
0
 

Author Comment

by:wotech
Comment Utility
Worked like a charm!  Thanks for the help.
0

Featured Post

How your wiki can always stay up-to-date

Quip doubles as a “living” wiki and a project management tool that evolves with your organization. As you finish projects in Quip, the work remains, easily accessible to all team members, new and old.
- Increase transparency
- Onboard new hires faster
- Access from mobile/offline

Join & Write a Comment

If you have heard of RFC822 date formats, they can be quite a challenge in SQL Server. RFC822 is an Internet standard format for email message headers, including all dates within those headers. The RFC822 protocols are available in detail at:   ht…
Ever wondered why sometimes your SQL Server is slow or unresponsive with connections spiking up but by the time you go in, all is well? The following article will show you how to install and configure a SQL job that will send you email alerts includ…
This video shows, step by step, how to configure Oracle Heterogeneous Services via the Generic Gateway Agent in order to make a connection from an Oracle session and access a remote SQL Server database table.
Viewers will learn how to use the UPDATE and DELETE statements to change or remove existing data from their tables. Make a table: Update a specific column given a specific row using the UPDATE statement: Remove a set of values using the DELETE s…

772 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

12 Experts available now in Live!

Get 1:1 Help Now