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
 SQL Server 2008 Forums
 Transact-SQL (2008)
 Insert rows where there is not matching data

Author  Topic 

boggyboy
Yak Posting Veteran

57 Posts

Posted - 2011-10-13 : 22:00:21
I want to insert rows into Table A where there are non-matching values in table B

Table A
ID, Cost, RowID
1, 100, 1
2, 122, 2
3, 88, 3

Table B
ID, Cost RowID
1, 100, 1
2, 150, 2
3, 88, 3

After Query runs I end up with the following in Table A
1, 100, 1
2, 122, 2
3, 88, 3
2, 150, 4


Nick W Saban

boggyboy
Yak Posting Veteran

57 Posts

Posted - 2011-10-13 : 22:55:20
Answering my own question

Insert into A
(ID,Cost)
(select * from B except select * from A)

Nick W Saban
Go to Top of Page
   

- Advertisement -