Please start any new threads on our new site at https://forums.sqlteam.com. We've got lots of great SQL Server experts to answer whatever question you can come up with.

 All Forums
 General SQL Server Forums
 New to SQL Server Programming
 change zero to space

Author  Topic 

usafelix
Posting Yak Master

165 Posts

Posted - 2015-01-30 : 04:23:15
I have some data like this , how to write query change to desire output like this.

percentage
1.10000000000000
1.2300000000000
3.0000000000

output
percentage
1.1
1.23
3.0

jleitao
Posting Yak Master

100 Posts

Posted - 2015-01-30 : 06:30:56
probably your percentage column is numeric, if you convert it to float the zeros will desapear

CONVERT(float, PERCENTAGE)




------------------------
PS - Sorry my bad english
Go to Top of Page

SwePeso
Patron Saint of Lost Yaks

30421 Posts

Posted - 2015-01-31 : 04:37:58
My question is "Why?".



Microsoft SQL Server MVP, MCT, MCSE, MCSA, MCP, MCITP, MCTS, MCDBA
Go to Top of Page

jleitao
Posting Yak Master

100 Posts

Posted - 2015-02-02 : 08:12:42
Why use a convert and not use a replace?!?

If you have, for example, a value like 10.320000000 and if you use a replace like REPLACE(percentage, '0','') your output will be 1.32 and not 10.32

Why i use a Conver and not a Cast? Because, i think it's more "user friendly" for begin users.

CONVERT(float, PERCENTAGE)
or
CAST(PERCENTAGE as float)

if your "why" it's about another thing, can you be more explicit?



------------------------
PS - Sorry my bad english
Go to Top of Page

SwePeso
Patron Saint of Lost Yaks

30421 Posts

Posted - 2015-02-03 : 05:15:20
I was asking the original poster.
Why then need for removing trailing zeroes.



Microsoft SQL Server MVP, MCT, MCSE, MCSA, MCP, MCITP, MCTS, MCDBA
Go to Top of Page
   

- Advertisement -