Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations bkrike on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Data retrieval

Status
Not open for further replies.

Otacustes

IS-IT--Management
Apr 15, 2005
40
GB
Hi,
I am trying to write a query that will read some data and insert it into another table.

I have tables set out like this:

Table1
======
ProductNo
Title
Qty

Table2
======
ProductNo
Description
Amount

This is legacy data which I am trying to use to build a table (Table3) - what I need to do is find which products from Table2 that are NOT in Table1 and then insert them into Table3.

I hope this makes sense to somebody?

If anyone can help writing a query to achieve this it would be greatly appreciated.

Kind regards
Ota
 
something like this...change the select statement to get whatever you want...

insert into table3
SELECT A.ProductNo FROM Table1 A
LEFT JOIN Table2 B
ON A.ProductNo = B.ProductNo
WHERE B.col1 IS NULL

-DNG
 
insert into table3
select * from table1 t1 left join table2 t2 on t1.ProductNo =t2.ProductNo
where t2.ProductNo is null

“I sense many useless updates in you... Useless updates lead to fragmentation... Fragmentation leads to downtime...Downtime leads to suffering..Fragmentation is the path to the darkside.. DBCC INDEXDEFRAG and DBCC DBREINDEX are the force...May the force be with you" --
 
i meant to say:

insert into table3
SELECT A.ProductNo FROM Table1 A
LEFT JOIN Table2 B
ON A.ProductNo = B.ProductNo
WHERE B.[red]ProductNo[/red] IS NULL

-DNG
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top