Jasmine
Jasmine

Reputation: 5326

How to identify or extract the rows where two column values (Amount fields) are different in SQL

Rather than manually going through millions of records, is there a way to find the records which has difference in two amount columns? Is there a query to do it for me?

For example, Table A contains ColA and ColB with amountss on this and the datatype is "Money" on both columns. There are few instances where values are different (It's decimal values, apparently, yeah? Yes, because its money field).

Can somebo0dy help me with a query to extract the rows with difference in money values?

Upvotes: 0

Views: 90

Answers (3)

Deepshikha
Deepshikha

Reputation: 10274

To consider rows where ColA or ColB are null you can write as:

select ColA, ColB
from TableA
where Isnull(ColA,0) - Isnull(ColB ,0) != 0

Demo

Upvotes: 1

Aayush Rathore
Aayush Rathore

Reputation: 180

In general, you can query rows having some conditions using where clause.

Select * from Table where Column1 operator Column2

So, here you can write:

Select * from TableA where ColA <> ColB

Upvotes: 0

Veera
Veera

Reputation: 3492

As both are same datatype. You just need to check ColA <> ColB.

SELECT * FROM TableA  WHERE ColA <> ColB 

Upvotes: 2

Related Questions