Solved

Replace string value to correspond with ID value

Posted on 2008-10-31
2
356 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

Efficient way to get backups off site to Azure

This user guide provides instructions on how to deploy and configure both a StoneFly Scale Out NAS Enterprise Cloud Drive virtual machine and Veeam Cloud Connect in the Microsoft Azure Cloud.

Question has a verified solution.

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

Suggested Solutions

Why is this different from all of the other step by step guides?  Because I make a living as a DBA and not as a writer and I lived through this experience. Defining the name: When I talk to people they say different names on this subject stuff l…
In this article we will get to know that how can we recover deleted data if it happens accidently. We really can recover deleted rows if we know the time when data is deleted by using the transaction log.
Viewers will learn how to use the INSERT statement to insert data into their tables. It will also introduce the NULL statement, to show them what happens when no value is giving for any given column.
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…

776 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