How to compare 2 table columns and insert the column name and column value in temp table in SQL?

Posted by Sundermagar under Sql Server on 5/5/2010 | Views : 3023 | Status : [Member] | Replies : 2
Hi Friends,

I have a question:

PROBLEM: I have a Table A with 100 columns Table B with 100 columns but column names are not same for Table A and Table B.

I need to compare each column of Table A and Table B and if column value does not matched then insert that particular column name and value to some temporary table.

The comparison should be for each column not for row.

Can any one tell how to do it any technique are welcomed whether using Cursor or Procs.

Thanks
Sunder

Sunder Magar


Responses

Posted by: Pavanandey on: 5/6/2010 [Member] Bronze

Up
0
Down


Let use suppose u have two table A, B with following Colums

A
-----------------
AID , ANAME, AAddress

and

B
-----------------
BID, BNAME, BADddress

now u can open a cursour on table a and compare each row coloum wise and increment a count variable if all the coloums matches else u can leave not increment the count,
one u have done with all the rows then u can check if count is equal to 100 u need not insert else insert in the row in the temp table

Thanks
Pavan Kumar
Mark Answer if this fits the need

Sundermagar, if this helps please login to Mark As Answer. | Alert Moderator

Posted by: Nandy on: 7/4/2010 [Member] Starter

Up
0
Down
Please go thru below links
http://weblogs.sqlteam.com/jeffs/archive/2004/11/10/2737.aspx
http://www.sqlteam.com/forums/topic.asp?TOPIC_ID=23054

Sundermagar, if this helps please login to Mark As Answer. | Alert Moderator

Login to post response