Solved

Replace string value to correspond with ID value

Posted on 2008-10-31
2
355 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
ID: 22851716
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
ID: 22852155
Worked like a charm!  Thanks for the help.
0

Featured Post

PRTG Network Monitor: Intuitive Network Monitoring

Network Monitoring is essential to ensure that computer systems and network devices are running. Use PRTG to monitor LANs, servers, websites, applications and devices, bandwidth, virtual environments, remote systems, IoT, and many more. PRTG is easy to set up & use.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Ever needed a SQL 2008 Database replicated/mirrored/log shipped on another server but you can't take the downtime inflicted by initial snapshot or disconnect while T-logs are restored or mirror applied? You can use SQL Server Initialize from Backup…
This article shows gives you an overview on SQL Server 2016 row level security. You will also get to know the usages of row-level-security and how it works
Via a live example combined with referencing Books Online, show some of the information that can be extracted from the Catalog Views in SQL Server.
Using examples as well as descriptions, and references to Books Online, show the documentation available for datatypes, explain the available data types and show how data can be passed into and out of variables.

863 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

20 Experts available now in Live!

Get 1:1 Help Now