Click here to Skip to main content
15,885,652 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Hi,

i have two identical tables called master and new.when i update master table its should compare with new table and return only mismatched columns.

What I have tried:

i have tried by using except but its returning all cloumns
Posted
Updated 12-Jun-16 19:54pm

1 solution

Here is two way to resolve your problem .
1. You can use the EXCEPT or INTERSECT set operators for this. for example

SQL
SELECT id, name FROM master.dbo.test
EXCEPT  -- or INTERSECT
SELECT id, name FROM test.dbo.testings


2. Use of Information Schema

SQL
select * 
FROM questions_table 
WHERE questioncolumn IN
(
  select column_name 
  from information_schema.columns where table_name='dynamic_table'
);
 
Share this answer
 
Comments
Veena Hosur 13-Jun-16 3:02am    
test.dbo.testings is other table ?
aarif moh shaikh 13-Jun-16 3:14am    
yes
Veena Hosur 13-Jun-16 3:23am    
tableA

field1 | field2 | field3 |

1 | 2 | 3 |
2 | 8 | 7 |
3 | 66 | 24 |
TableB

field1 | field2 | field3 |

1 | 2 | 3 |
2 | 8 | 7 |
3 | 66 | 57 |
Here i want to return mandatory field field1 and field3 whose value is not matching with other table. Result should be like,

field1 | field3 |

3 | 57 |
Veena Hosur 13-Jun-16 3:23am    
it wil return all fields na

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900