I have following 2 tables TableA and TableB need to find the difference and get the result from TableA if there is any changes in any of the Cost columns. Ignore the same records from TableA and TableB I have tried with EXCEPT which is yielding the wrong result.
TABLEA
| JobNo | Brand | Cost1 | Cost2 | Cost3 | Cost4 | Cost5 |
| ------------ | ------------ | ------------ | ------------ | ------------ | ------------ | ------------ |
| 175196 | Vintage | 216347 | 217429 | 218516 | 219609 | 220707 |
| 200330 | Vintage | 427169 | 429305 | 431451 | 433608 | 435776 |
| 211746 | Modern | 285621 | 287049 | 288484 | 289927 | 291376 |
TABLEB
JobNo | Brand | Cost1 | Cost2 | Cost3 | Cost4 | Cost5 |
---|---|---|---|---|---|---|
175196 | Vintage | 227030 | 228165 | 229306 | 230453 | 231605 |
200330 | Vintage | 444551 | 446774 | 449007 | 451252 | 453509 |
211746 | Modern | 285621 | 287049 | 288484 | 289927 | 291376 |
Result Expected
JobNo | Brand | Cost1 | Cost2 | Cost3 | Cost4 | Cost5 |
---|---|---|---|---|---|---|
175196 | Vintage | 216347 | 217429 | 218516 | 219609 | 220707 |
200330 | Vintage | 427169 | 429305 | 431451 | 433608 | 435776 |
SELECT JobNo,Brand,Cost1,Cost2,Cost3,Cost4,Cost5 FROM TableA(NOLOCK)
EXCEPT
SELECT JobNo,Brand,Cost1,Cost2,Cost3,Cost4,Cost5 FROM TableB(NOLOCK)
2条答案
按热度按时间enyaitl31#
find the differences between TableA and TableB based on the Cost columns and retrieve the results from TableA if there are any changes
You can use this:
kxe2p93d2#
The EXCEPT is right, you can see it here:
http://sqlfiddle.com/#!18/f6fc2/2