May 20, 2014 at 12:30 pm
When I execute the below query i'm getting 801075 as result. How can I get 801075.003 as result?
DECLARE @int float = 801075.003
SELECT CAST(@int AS VARCHAR(30))
May 20, 2014 at 12:37 pm
sql server developer (5/20/2014)
When I execute the below query i'm getting 801075 as result. How can I get 801075.003 as result?DECLARE @int float = 801075.003
SELECT CAST(@int AS VARCHAR(30))
You have a float with a name of @int!!! ROFL.
The problem here is that float is not an exact number, it is an approximate datatype. You will first have to get this into an exact datatype and then to varchar.
SELECT cast(convert(numeric(9,3), @int) as varchar)
_______________________________________________________________
Need help? Help us help you.
Read the article at http://www.sqlservercentral.com/articles/Best+Practices/61537/ for best practices on asking questions.
Need to split a string? Try Jeff Modens splitter http://www.sqlservercentral.com/articles/Tally+Table/72993/.
Cross Tabs and Pivots, Part 1 – Converting Rows to Columns - http://www.sqlservercentral.com/articles/T-SQL/63681/
Cross Tabs and Pivots, Part 2 - Dynamic Cross Tabs - http://www.sqlservercentral.com/articles/Crosstab/65048/
Understanding and Using APPLY (Part 1) - http://www.sqlservercentral.com/articles/APPLY/69953/
Understanding and Using APPLY (Part 2) - http://www.sqlservercentral.com/articles/APPLY/69954/
May 20, 2014 at 2:04 pm
Sean,
Thanks much! That worked.
May 20, 2014 at 2:19 pm
sql server developer (5/20/2014)
Sean,Thanks much! That worked.
You're welcome. Glad that worked for you.
_______________________________________________________________
Need help? Help us help you.
Read the article at http://www.sqlservercentral.com/articles/Best+Practices/61537/ for best practices on asking questions.
Need to split a string? Try Jeff Modens splitter http://www.sqlservercentral.com/articles/Tally+Table/72993/.
Cross Tabs and Pivots, Part 1 – Converting Rows to Columns - http://www.sqlservercentral.com/articles/T-SQL/63681/
Cross Tabs and Pivots, Part 2 - Dynamic Cross Tabs - http://www.sqlservercentral.com/articles/Crosstab/65048/
Understanding and Using APPLY (Part 1) - http://www.sqlservercentral.com/articles/APPLY/69953/
Understanding and Using APPLY (Part 2) - http://www.sqlservercentral.com/articles/APPLY/69954/
Viewing 4 posts - 1 through 3 (of 3 total)
You must be logged in to reply to this topic. Login to reply