MS SQL/sql query

Advertisement


zderick wrote at 2012-10-29 11:51:14
Hi.



You may use "EXCEPT" if you will only ADD new records from one table to the other.



-- Sample SQL Code

CREATE TABLE #table1

(column1 int

,column2 varchar(20))



CREATE TABLE #table2

(column1 int

,column2 varchar(20))



INSERT INTO #table1 (column1, column2)

SELECT 1,'Roderick' UNION ALL

SELECT 2,'Josh' UNION ALL

SELECT 3,'Allain'



INSERT INTO #table2 (column1, column2)

SELECT 1,'Roderick' UNION ALL

SELECT 2,'Josh'



SELECT * FROM #table1

SELECT * FROM #table2



INSERT INTO #table2

SELECT * FROM #table1 a

EXCEPT

SELECT * FROM #table2 a



SELECT * FROM #table2



DROP TABLE #table1

DROP TABLE #table2


MS SQL

All Answers


Answers by Expert:


Ask Experts

Volunteer


Jwalant Natvarlal Soneji

Expertise

Questions related to query optimization, finding complex results.

Experience

Experience in the area: I have been working in the field since 2005 year. Education/Credentials: BE IT, First Class, 2005 Batch.

Publications
http://jwalantsoneji.com

Education/Credentials
BE IT, India

Awards and Honors
MCP

©2016 About.com. All rights reserved.