Take the 2-minute tour ×
Database Administrators Stack Exchange is a question and answer site for database professionals who wish to improve their database skills and learn from others in the community. It's 100% free, no registration required.

I have a T-SQL query :

select CAST(0 as float(53)),CONVERT(nvarchar(max),CAST(0 as float(53)),128)

the output of which is

0,0.0E0

Can some one explain why it is not 0,0 ? The database is SQL Server 2008.

Thanks

share|improve this question
2  
According to msdn, format 128 is deprecated and might not be supported in future releases. –  Andomar Mar 17 '12 at 16:55
    
@Andomar: I think you need to move your comment as an answer. –  a1ex07 Mar 18 '12 at 0:25
    
Why not to use 0: select CAST(0 as float(53)),CONVERT(nvarchar(max),CAST(0 as float(53)),0) –  msi77 Mar 18 '12 at 6:25
    
@Andomar : I know format 128 is deprecated but this is the best we could have done to remove trailing 0's when the data is numeric. We plan to stick to SQL Server 2008 for some time before we move to other version. Thanks –  Egalitarian Mar 18 '12 at 10:33
    
@msi77 : I want to know why in this case ? –  Egalitarian Mar 18 '12 at 10:38
show 6 more comments

1 Answer

Syntax for CONVERT:

 CONVERT ( data_type [ ( length ) ] , expression [ , style ] )

[style] for float data type :

0 (default)   A maximum of 6 digits. Use in scientific notation, when appropriate.
1 Always 8 digits. Always use in scientific notation.
2 Always 16 digits. Always use in scientific notation.
126, 128, 129 Included for legacy reasons and might be deprecated in a future release.

You can use below command to get expected result :

CONVERT(nvarchar(max),CAST(0 as float(53)),0)
share|improve this answer
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.