| Author |
Topic |
|
MageshkumarM
Yak Posting Veteran
61 Posts |
Posted - 2011-02-04 : 04:53:24
|
Hi,I need to match the values from two different tables,fr Ex.*****Table1******column1 --- column2 --- column3 ---- column4 --- column5122 ----- 140 ---- 25 ---- 65 ---- 95 Table2******column1 --- column2 --- column3 ---- column4 --- column5122 ---- 142 ------ 25 ----- null ---- 95if column value not same (or) not matching, i would like to print the message,print 'column2 missing'print 'column4 missing'Anyone give me some suggestion to find this...!MAG,Start with the new Idea.. http://mageshkumarm.blogspot.com/ |
|
|
webfred
Master Smack Fu Yak Hacker
8781 Posts |
Posted - 2011-02-04 : 05:07:08
|
You won't have two tables with only one row in each table.So you need to have a relation between them.How will you know which row from table1 has to be compared to which row in table2? No, you're never too old to Yak'n'Roll if you're too young to die. |
 |
|
|
SwePeso
Patron Saint of Lost Yaks
30421 Posts |
Posted - 2011-02-04 : 05:18:19
|
[code]declare @table1 table ( column1 int, column2 int, column3 int, column4 int, column5 int )insert @table1values (122, 140, 25, 65, 95), (1, 2, 3, 4, 5), (11, 2, 3, 4, 5)declare @table2 table ( column1 int, column2 int, column3 int, column4 int, column5 int )insert @table2values (122, 142, 25, null, 95), (1, 2, 3, 4, 5), (10, 2, 3, 4, 5)select case when t2.column1 is null then '@Table2 is missing a record with value ' + ltrim(str(t1.column1)) + ' in column1.' when t1.column1 is null then '@Table1 is missing a record with value ' + ltrim(str(t2.column1)) + ' in column1.' when binary_checksum(t1.column2, t1.column3, t1.column4, t1.column5) = binary_checksum(t1.column2, t1.column3, t1.column4, t1.column5) then 'column1 value ' + ltrim(str(t2.column1)) + ' is a perfect match.' else 'There is a discrepancy between the tables for column1 value ' + ltrim(str(t2.column1)) + '.' endfrom @table1 as t1full join @table2 as t2 on t2.column1 = t1.column1[/code] N 56°04'39.26"E 12°55'05.63" |
 |
|
|
MageshkumarM
Yak Posting Veteran
61 Posts |
Posted - 2011-02-04 : 06:40:34
|
thank u Mr. peso,MAG,Start with the new Idea.. http://mageshkumarm.blogspot.com/ |
 |
|
|
|
|
|