Please start any new threads on our new site at https://forums.sqlteam.com. We've got lots of great SQL Server experts to answer whatever question you can come up with.

 All Forums
 General SQL Server Forums
 New to SQL Server Programming
 aggregate a new table

Author  Topic 

allan8964
Posting Yak Master

249 Posts

Posted - 2011-11-15 : 00:09:05
Hi there,

Here is the scenario:
tableA has columns of SalesID, SalesDate, CustomerName
tableB has columns of CustomerID, CustomerName
Now I need to insert tableA to tableC with columns as:
SalesID, SalesDate, CustomerID

How should I do this? Thanks in advance.

visakh16
Very Important crosS Applying yaK Herder

52326 Posts

Posted - 2011-11-15 : 00:20:32
[code]
insert into tableC
select a.SalesID, a.SalesDate,b.CustomerID
from tableA a
inner join tableB b
ON b.CustomerName = a.CustomerName
[/code]

------------------------------------------------------------------------------------------------------
SQL Server MVP
http://visakhm.blogspot.com/

Go to Top of Page

madhivanan
Premature Yak Congratulator

22864 Posts

Posted - 2011-11-15 : 04:48:11
Why do you need a seperate table for this as you can show it in SELECT statement or create a view based on it?

Madhivanan

Failing to plan is Planning to fail
Go to Top of Page

allan8964
Posting Yak Master

249 Posts

Posted - 2011-11-15 : 12:33:02
Thanks visakh16, it works.
Go to Top of Page
   

- Advertisement -