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
 How to compare data from 2 diff column and table

Author  Topic 

Ismee
Starting Member

2 Posts

Posted - 2012-12-06 : 10:09:17
1. Table A colum Z
2. Table H column Y from anothe db
Data from 1. will be inserted into 2.
I need to check if all data from 1. are inserted into 2. Successfully.
Not only verify the records.but the data. Like data has abcd1234 then it should also inserted into 2. exactly
Sorry that I am rookie in SQL query. Can it be done via query and return true/ false result? And pointing which data is not inserted if false?

shilpash
Posting Yak Master

103 Posts

Posted - 2012-12-06 : 10:16:36
select COLUMNZ FROM TABLEA
EXCEPT
SELECT COLUMNY FROM TABLEH

IF YOU SEE 0 RECORDS,IT MEANS ALL DATAS ARE SAME,,IF ANY ROWS, THEN DATA FOR THAT ROW IS DIFFERENT.
Go to Top of Page

Ismee
Starting Member

2 Posts

Posted - 2012-12-06 : 19:47:15
Thanks.
How do I compare when the table is located at different db?
Can I use multiple except to compare more than 2 table?
Go to Top of Page

sodeep
Master Smack Fu Yak Hacker

7174 Posts

Posted - 2012-12-06 : 21:00:16
[code]select COLUMNZ FROM DBNAME.dbo.TABLEA
EXCEPT
SELECT COLUMNY FROM DBNAME.dbo.TABLEH[/code]
Go to Top of Page
   

- Advertisement -