You could round
the price to two decimal places, and then compare it to the original value:
WHERE ROUND([price], 2) <> [price]
Question
I've got the following table schema:
CREATE TABLE [items] (
[qty] INT NOT NULL,
[price] MONEY NOT NULL,
[subtotal] MONEY NOT NULL,
...
);
Some of the rows look like this:
+--------+-------+----------+
| qty | price | subtotal |
+--------+-------+----------+
| 100000 | 0.017 | 1700.00 |
+--------+-------+----------+
I don't like fractional cents and this data isn't that important, so I want to adjust any rows that have fractional-cent prices. So I'd change the example row above to look like this instead:
+-----+---------+----------+
| qty | price | subtotal |
+-----+---------+----------+
| 1 | 1700.00 | 1700.00 |
+-----+---------+----------+
If I used this query:
SELECT * FROM [items]
WHERE ([price] * 1000) % 10 > 0
...that would get me all the rows where the price goes out to precision 3. And that's useful for this example where the price is 1.7¢. But what if it's something like 0.002¢ (i.e. precision 5)? Do I need to write a query with a bunch of OR statements for each precision I think it might be, or is there a simpler way to say WHERE [price] (has precision ≥ 3)
?
Solution
You could round
the price to two decimal places, and then compare it to the original value:
WHERE ROUND([price], 2) <> [price]