Please start any new threads on our new
site at https://forums.sqlteam.com. We've got lots of great SQL Server
experts to answer whatever question you can come up with.
| Author |
Topic |
|
o9z
Starting Member
23 Posts |
Posted - 2008-01-30 : 08:36:21
|
| For example, I have 2 tables that have very similar fieldsTable 1 Table 2ShipRpt ShipRptinvoice invoicetotal sold total soldIs it possible to compare each of these fields and return any record that has non matching data? I would join the tables on the shipping report or invoice and only compare the total sold field. If the invoices match and the total sold is different in each table, can I just return the 1 record? |
|
|
sakets_2000
Master Smack Fu Yak Hacker
1472 Posts |
Posted - 2008-01-30 : 08:44:07
|
| select * from table1 ajoin table2 bon a.invoice=b.invoiceand a.[total sold]<>b.[total sold] |
 |
|
|
SwePeso
Patron Saint of Lost Yaks
30421 Posts |
Posted - 2008-01-30 : 08:44:21
|
SELECT ShipRpt, InvoiceFROM (SELECT ShipRpt, Invoice, TotalSold, 'Table1' AS TableNam FROM TableUNION ALLSELECT ShipRpt, Invoice, TotalSold, 'Table2' FROM Table) AS xGROUP BY ShipRpt, InvoiceHAVING COUNT(*) <> 2OR sum(case when tablename = 'table1' then totalsold else 0 End) <> sum(case when tablename = 'table2' then totalsold else 0 End) E 12°55'05.25"N 56°04'39.16" |
 |
|
|
|
|
|