Reputation: 7
The following expression is returning decimal value
TO_VARCHAR(COLUMN_NAME + 10)
let say the value of column is 80 , it is ruturning 90.00000 and the COLUMN_NAME in source is number
what to add or change to get the return value as varchar as 90 instead of 90.0000
Upvotes: 0
Views: 337
Reputation: 7369
I would just cast the sum to an integer, first, and then to a varchar.
SELECT (COLUMN_NAME + 10)::INT::VARCHAR;
You can also use SQL Format Models here: https://docs.snowflake.com/en/sql-reference/sql-format-models.html, but I find them difficult to work with, since you mostly need to know the fixed decimal places of your result, first. For example,
SELECT TO_VARCHAR('40' + 10, '99');
or
SELECT TO_VARCHAR('40' + 10, '999');
both work, but this doesn't:
SELECT TO_VARCHAR('400' + 10, '99');
So, I'd just stick with the first one if I were you, it's just easier.
Upvotes: 2