|
Posted by Erland Sommarskog on 06/12/07 21:38
jb1 (james.benson1@googlemail.com) writes:
> On 12 Jun, 16:24, undercups <d...@woodace.co.uk> wrote:
>> The answer is to write 3 queries, 1 for each situation you describe
>> and link the output using the UNION ALL statement
>>
>> Something like
>>
>> SELECT a.id, a.col1, a.col2, a.col3, b.col4 FROM table1 a JOIN table2
>> b on a.id = b.id
>> WHERE a.col1 <> b.col1
Note here that you should probably compare all columns. If columns can
be nullable, this can be quite hairy.
> That's great! Thank you. I'll have a look into this.
> Do you have any ideas how I can add the above mentioned STATUS column
> after each returned row? eg. If row is different in tbl_B from tbl_A
> then add 'M' at the end of the row, as has Master data. something
> like.. ("col1.value","col2.value","col3.value","M")
Just att the desired status letter to the column list of the queries,
for instance:
SELECT a.id, a.col1, a.col2, a.col3, b.col4, 'M' AS status
--
Erland Sommarskog, SQL Server MVP, esquel@sommarskog.se
Books Online for SQL Server 2005 at
http://www.microsoft.com/technet/prodtechnol/sql/2005/downloads/books.mspx
Books Online for SQL Server 2000 at
http://www.microsoft.com/sql/prodinfo/previousversions/books.mspx
Navigation:
[Reply to this message]
|