Solved

Replace string value to correspond with ID value

Posted on 2008-10-31
2
362 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
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

Get 15 Days FREE Full-Featured Trial

Benefit from a mission critical IT monitoring with Monitis Premium or get it FREE for your entry level monitoring needs.
-Over 200,000 users
-More than 300,000 websites monitored
-Used in 197 countries
-Recommended by 98% of users

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…
In this article we will learn how to fix  “Cannot install SQL Server 2014 Service Pack 2: Unable to install windows installer msi file” error ?
This video shows how to set up a shell script to accept a positional parameter when called, pass that to a SQL script, accept the output from the statement back and then manipulate it in the Shell.
Via a live example, show how to shrink a transaction log file down to a reasonable size.

632 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