Compare row to row | SQL Server Performance Forums

SQL Server Performance Forum – Threads Archive

Compare row to row

I have this 2 tables which are same structure: Table 1:
]http://img22.imageshack.us/img22/8145/tabla15ut.jpg] Table 2:
]http://img312.imageshack.us/img312/3695/tabla24rk.jpg] I make this instruction to compare de differences between tables: SELECT codigo, nombre, apellido
FROM [SELECT ‘Tabla A’ as TableName, Tabla1.codigo, Tabla1.nombre, Tabla1.apellido
FROM Tabla1
UNION ALL
SELECT ‘Tabla B’ as TableName, Tabla2.codigo, Tabla2.nombre, Tabla2.apellido
FROM Tabla2
]. AS tmp
GROUP BY codigo, nombre, apellido
HAVING COUNT(*) = 1
ORDER BY codigo; And this is the result:
http://img138.imageshack.us/img138/497/result8vx.jpg
Question: How I can put in a new column tmp.TableName without change the result? Thanks!!
Try Max(TableName). Robert.

Kindly post the thread in relevant forums only, moved from Analysis forum. Satya SKJ
Moderator
http://www.SQL-Server-Performance.Com/forum
This posting is provided “AS IS” with no rights for the sake of knowledge sharing.
Thanks RGKN, it’s a valid solution!!
]]>