shole shole - 2 months ago 8
SQL Question

T-SQL select row if one specific column's decimal part is not 0

I have a table with one of the columns :

cost
, it is of decimal type with 2 d.p.

Now I would like to select all rows from this table where
cost
's decimal part is not 0

For example, I do not select the row if
cost
is 150.00 or 222.00, but would like to select if
cost
is 0.20 or 123.12, etc.

How can this be done in a single select query?

Answer

For rows where there is a zero decimal part Floor(cost) will equal cost and it won't where there is a non zero decimal part.

SELECT *
FROM YourTable
WHERE Floor(cost) <> cost;