I am trying to run a simple report where one of the columns is a float type, but I want to change the result to show a string (I think that is the best way). If the value of the float column is 101 or 201, I want the result to show as ‘101, 201’ and other values to show as they are in the table.
This is what I’ve been messing with, but the results are incorrect:
SELECT float_column, CASE WHEN (STR(float_column, 10, 16)) IN ('101', '201') THEN '101,201' ELSE column END AS float_column, column2, column3 FROM database.table ORDER BY float_column
Why wouldn’t you use number comparisons?
SELECT float_column, CASE WHEN float_column in (101, 201) THEN '101,201' ELSE CAST(float_column as VARCHAR(255)) END AS string_column, column2, column3 FROM database.table ORDER BY float_column;
I don’t usually advise equality comparisons for floats — but the above could be adjusted by converting to an integer to numeric. I don’t see what the conversion to the string is doing for you.