Solved

How to insert data into SQL table where a column name equals a different column namefrom another table.

Posted on 2008-10-27
2
942 Views
Last Modified: 2012-05-05
I am a fairly new beginner with SQL and I having a couple of issues.

I want to insert data in a pre-existing table from a separate table. For instance, table A has a column entitled prod_id and table B has a column titled sold_prod_id. These values are the same, they are just named differently within the two tables (ITable B was prodived and I created table A based on a provided ERD). I have created a column within table A entitled sold_date. Table B contains the sold_date information, but I need it within table A. I have tried a WHERE clause and an INNER JOIN.

WHERE clause:

insert into a (sold_date)
select sold_date
from b
where a.prod_id = b.sold_prod_id

This is where I enounter the "The multi-part identifier 'a.prod_id' could not be bound."

INNER JOIN:

insert into a (sold_date)
select sold_date
from b
inner join a on b.sold_prod_id = a.prod_id

The inner join query inputs sold_date, but after all of the data within table a. It doesn't put the sold_date on the same row associated with the prod_id. I hope this isn't too confusing and any help is greatly appreciated.
0
Comment
Question by:MISKid08
2 Comments
 
LVL 142

Accepted Solution

by:
Guy Hengel [angelIII / a3] earned 125 total points
ID: 22817217
I think you want a UPDATE:
UPDATE a
  SET sold_date = b.sold_date
from b
inner join a 
  on b.sold_prod_id = a.prod_id

Open in new window

0
 

Author Closing Comment

by:MISKid08
ID: 31510539
You're amazing. Thanks for helping a beginner.
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

Suggested Solutions

JSON is being used more and more, besides XML, and you surely wanted to parse the data out into SQL instead of doing it in some Javascript. The below function in SQL Server can do the job for you, returning a quick table with the parsed data.
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…
Using examples as well as descriptions, and references to Books Online, show the documentation available for date manipulation functions and by using a select few of these functions, show how date based data can be manipulated with these functions.
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…

813 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

13 Experts available now in Live!

Get 1:1 Help Now