I have two tables as:
table1
tablename tablecount
a 1
b 2
c 3
d 4
.
.
table2
tablename tablecount
a 1
b 2
c 10
d 11
.
.
.
How do I write a SP to do a COMPARE and give me the table names that are
different along with count differences.
Thanks,
TomdThis can basically be done by joining table1 with table2 and selecting where
tablecount <> tablecount.
select table1.tablename, table1.tablecount - table2.tablecount as difference
from table1
join table2 on table2.tablename = table1.tablename
where table1.tablecount <> table2.tablecount
"tom d" <tomd@.discussions.microsoft.com> wrote in message
news:C2BB644B-1849-45AF-A72A-38A5E105F8F9@.microsoft.com...
>I have two tables as:
> table1
> tablename tablecount
> a 1
> b 2
> c 3
> d 4
> .
> .
> table2
> tablename tablecount
> a 1
> b 2
> c 10
> d 11
> .
> .
> .
> How do I write a SP to do a COMPARE and give me the table names that are
> different along with count differences.
> Thanks,
> Tomd
>|||Tom,
Try:
SELECT A.TABLENAME, A.TABLECOUNT AS 'COUNT OF TABLE1',B.TABLECOUNT AS
'COUNT OF TABLE2'
FROM TABLE1 A JOIN TABLE2 B
ON A.TABLENAME = B.TABLENAME
WHERE A.TABLECOUNT <> B.TABLECOUNT
HTH
Jerry
"tom d" <tomd@.discussions.microsoft.com> wrote in message
news:C2BB644B-1849-45AF-A72A-38A5E105F8F9@.microsoft.com...
>I have two tables as:
> table1
> tablename tablecount
> a 1
> b 2
> c 3
> d 4
> .
> .
> table2
> tablename tablecount
> a 1
> b 2
> c 10
> d 11
> .
> .
> .
> How do I write a SP to do a COMPARE and give me the table names that are
> different along with count differences.
> Thanks,
> Tomd
>
Thursday, March 8, 2012
DATA COMPARE Question??
Labels:
10d,
astable1tablename,
compare,
database,
microsoft,
mysql,
oracle,
server,
sql,
table2tablename,
tablecounta,
tables,
write
Subscribe to:
Post Comments (Atom)
No comments:
Post a Comment