Click here to monitor SSC
SQLServerCentral is supported by Redgate
 
Log in  ::  Register  ::  Not logged in
 
 
 


Row-by-Row comparison


Row-by-Row comparison

Author
Message
rvkhadava
rvkhadava
SSC Rookie
SSC Rookie (28 reputation)SSC Rookie (28 reputation)SSC Rookie (28 reputation)SSC Rookie (28 reputation)SSC Rookie (28 reputation)SSC Rookie (28 reputation)SSC Rookie (28 reputation)SSC Rookie (28 reputation)

Group: General Forum Members
Points: 28 Visits: 79
I have two tables, stg,main with the same structure.Each day data is refeshed into stg from the flat file. And from there into main.Before the main table is loaded,I need to validate if the data in all the columns of the row is matching.The main challenge is I have 100 columns in these tables. Can any one recommend me of a optimal solution to compare data across the tables ?The bottom line is I should not create duplicate rows into the main table.

Thanks in Advance.
Mark Cowne
Mark Cowne
SSCrazy
SSCrazy (2.1K reputation)SSCrazy (2.1K reputation)SSCrazy (2.1K reputation)SSCrazy (2.1K reputation)SSCrazy (2.1K reputation)SSCrazy (2.1K reputation)SSCrazy (2.1K reputation)SSCrazy (2.1K reputation)

Group: General Forum Members
Points: 2091 Visits: 22781
Suggest you look at EXCEPT (and maybe INTERSECT) in BOL

____________________________________________________

Deja View - The strange feeling that somewhere, sometime you've optimised this query before

How to get the best help on a forum

http://www.sqlservercentral.com/articles/Best+Practices/61537




Mayank Khatri
Mayank Khatri
SSCommitted
SSCommitted (1.8K reputation)SSCommitted (1.8K reputation)SSCommitted (1.8K reputation)SSCommitted (1.8K reputation)SSCommitted (1.8K reputation)SSCommitted (1.8K reputation)SSCommitted (1.8K reputation)SSCommitted (1.8K reputation)

Group: General Forum Members
Points: 1811 Visits: 1692
search google on TableDiff utility, it comes with SQL 2005 installation used for table comparisons just for the kind of task u r looking for.
rvkhadava
rvkhadava
SSC Rookie
SSC Rookie (28 reputation)SSC Rookie (28 reputation)SSC Rookie (28 reputation)SSC Rookie (28 reputation)SSC Rookie (28 reputation)SSC Rookie (28 reputation)SSC Rookie (28 reputation)SSC Rookie (28 reputation)

Group: General Forum Members
Points: 28 Visits: 79
Sincere Thanks for coming up with your suggestions.At this point I have tried out Except operator and this seems to be working reasonably well for me.
SQLQuest29
SQLQuest29
Right there with Babe
Right there with Babe (746 reputation)Right there with Babe (746 reputation)Right there with Babe (746 reputation)Right there with Babe (746 reputation)Right there with Babe (746 reputation)Right there with Babe (746 reputation)Right there with Babe (746 reputation)Right there with Babe (746 reputation)

Group: General Forum Members
Points: 746 Visits: 4310
rvkhadava (6/5/2009)
I have two tables, stg,main with the same structure.Each day data is refeshed into stg from the flat file. And from there into main.Before the main table is loaded,I need to validate if the data in all the columns of the row is matching.The main challenge is I have 100 columns in these tables. Can any one recommend me of a optimal solution to compare data across the tables ?The bottom line is I should not create duplicate rows into the main table.

Thanks in Advance.


Hi,

I have implemented the same task using SSIS and it works like a charm. I have used lookup table task in SSIS.

http://www.sqlis.com/post/Get-all-from-Table-A-that-isnt-in-Table-B.aspx ===> use method 2, it works for me.

Hope this helps,

\\K
[http://sqlquest.blogspot.com/]

______________________________________________________________________________________________________________________________________________________________________________________
HTH !
Kin
MCTS : 2005, 2008
Active SQL Server Community Contributor :-)
Gary Stacey
Gary Stacey
SSC-Addicted
SSC-Addicted (446 reputation)SSC-Addicted (446 reputation)SSC-Addicted (446 reputation)SSC-Addicted (446 reputation)SSC-Addicted (446 reputation)SSC-Addicted (446 reputation)SSC-Addicted (446 reputation)SSC-Addicted (446 reputation)

Group: General Forum Members
Points: 446 Visits: 288
Hi,

Looking for a method of comparing rows in the same table, I ran across this thread. I thought I would add my 2p to the debate:


SET @result = 0

IF EXISTS (SELECT EX.DocumentID FROM
(SELECT DocumentID, DocTitle, SortLetter, SortNumber FROM
PMProcessProcedures WHERE PMProcessID = @ID
EXCEPT
SELECT DocumentID, DocTitle, SortLetter, SortNumber FROM
PMProcessProcedures WHERE PMProcessID = @Approved) EX)

SET @result = 1



This will set @result if the two rows are different.

Hope this helps someone...
Sheraz.Mirza
Sheraz.Mirza
Valued Member
Valued Member (60 reputation)Valued Member (60 reputation)Valued Member (60 reputation)Valued Member (60 reputation)Valued Member (60 reputation)Valued Member (60 reputation)Valued Member (60 reputation)Valued Member (60 reputation)

Group: General Forum Members
Points: 60 Visits: 294
Here is your Solution

http://www.sqlservercentral.com/scripts/Table+Data+Comparison/141216/

get the SQL Statement after running procedure and then change EXISTS with NOT EXISTS and you all done.

Sheraz Mirza:Hehe
Lynn Pettis
Lynn Pettis
SSC-Insane
SSC-Insane (24K reputation)SSC-Insane (24K reputation)SSC-Insane (24K reputation)SSC-Insane (24K reputation)SSC-Insane (24K reputation)SSC-Insane (24K reputation)SSC-Insane (24K reputation)SSC-Insane (24K reputation)

Group: General Forum Members
Points: 24171 Visits: 37936
Just an FYI, this is 6 year old thread.

Cool
Lynn Pettis

For better assistance in answering your questions, click here
For tips to get better help with Performance Problems, click here
For Running Totals and its variations, click here or when working with partitioned tables
For more about Tally Tables, click here
For more about Cross Tabs and Pivots, click here and here
Managing Transaction Logs

SQL Musings from the Desert Fountain Valley SQL (My Mirror Blog)
Go


Permissions

You can't post new topics.
You can't post topic replies.
You can't post new polls.
You can't post replies to polls.
You can't edit your own topics.
You can't delete your own topics.
You can't edit other topics.
You can't delete other topics.
You can't edit your own posts.
You can't edit other posts.
You can't delete your own posts.
You can't delete other posts.
You can't post events.
You can't edit your own events.
You can't edit other events.
You can't delete your own events.
You can't delete other events.
You can't send private messages.
You can't send emails.
You can read topics.
You can't vote in polls.
You can't upload attachments.
You can download attachments.
You can't post HTML code.
You can't edit HTML code.
You can't post IFCode.
You can't post JavaScript.
You can post emoticons.
You can't post or upload images.

Select a forum

































































































































































SQLServerCentral


Search