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
947 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
[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 143

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

Enroll in May's Course of the Month

May’s Course of the Month is now available! Experts Exchange’s Premium Members and Team Accounts have access to a complimentary course each month as part of their membership—an extra way to increase training and boost professional development.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
SQL Server how to create a DYNAMIC TABLE? 11 51
T-SQL Query 9 35
Datatable / Dates ? 4 30
Delete duplicates from SQL Server table 2 26
International Data Corporation (IDC) prognosticates that before the current the year gets over disbursing on IT framework products to be sent in cloud environs will be $37.1B.
For both online and offline retail, the cross-channel business is the most recent pattern in the B2C trade space.
Via a live example, show how to extract information from SQL Server on Database, Connection and Server properties
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.

734 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