?
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
Medium Priority
?
953 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 500 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

Free learning courses: Active Directory Deep Dive

Get a firm grasp on your IT environment when you learn Active Directory best practices with Veeam! Watch all, or choose any amount, of this three-part webinar series to improve your skills. From the basics to virtualization and backup, we got you covered.

Question has a verified solution.

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

This article explains how to reset the password of the sa account on a Microsoft SQL Server.  The steps in this article work in SQL 2005, 2008, 2008 R2, 2012, 2014 and 2016.
A Stored Procedure in Microsoft SQL Server is a powerful feature that it can be used to execute the Data Manipulation Language (DML) or Data Definition Language (DDL). Depending on business requirements, a single Stored Procedure can return differe…
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.
This is Part 3 in a 3-part series on Experts Exchange to discuss error handling in VBA code written for Excel. Part 1 of this series discussed basic error handling code using VBA. http://www.experts-exchange.com/videos/1478/Excel-Error-Handlin…
Suggested Courses

770 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