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
 decimal

Author  Topic 

peace
Constraint Violating Yak Guru

420 Posts

Posted - 2014-01-21 : 21:05:06
i have value with data type nvarchar:

total
000000854.00
000000042.00
000000065.17
000000000024
000000000.24

how can i convert to decimal and remove 0 infront? but those with 0.xx would not remove the 0 after the dote.

total
854.00
42.00
65.17
24
0.24

khtan
In (Som, Ni, Yak)

17689 Posts

Posted - 2014-01-21 : 21:10:57
[code]convert( decimal(10,2) , total )[/code]

quote:
how can i convert to decimal and remove 0 infront? but those with 0.xx would not remove the 0 after the dote.

you don't need to worry about that if it is decimal


KH
[spoiler]Time is always against us[/spoiler]

Go to Top of Page

peace
Constraint Violating Yak Guru

420 Posts

Posted - 2014-01-21 : 21:23:41
quote:
Originally posted by khtan

convert( decimal(10,2) , total )


quote:
how can i convert to decimal and remove 0 infront? but those with 0.xx would not remove the 0 after the dote.

you don't need to worry about that if it is decimal


KH
[spoiler]Time is always against us[/spoiler]





im still getting the same output.
Go to Top of Page

khtan
In (Som, Ni, Yak)

17689 Posts

Posted - 2014-01-21 : 21:44:30
show your query


KH
[spoiler]Time is always against us[/spoiler]

Go to Top of Page

peace
Constraint Violating Yak Guru

420 Posts

Posted - 2014-01-21 : 21:52:03
what i meant is the data originally as nvarchar(50)

total
000000854.00
000000042.00
000000065.17
000000000024
000000000.24
.
.
.
.

i wanted to convert into decimal and remove the 0 infront to be like this:

total
854.00
42.00
65.17
24
0.24
.
.
.
.

is it possible?
Go to Top of Page

khtan
In (Som, Ni, Yak)

17689 Posts

Posted - 2014-01-21 : 22:32:22
update back to the table ?

update yourtable
set total = convert(varchar(10), convert( decimal(10,2) , total ) )



KH
[spoiler]Time is always against us[/spoiler]

Go to Top of Page

peace
Constraint Violating Yak Guru

420 Posts

Posted - 2014-01-21 : 23:05:00
working fine.

Thanks
Go to Top of Page
   

- Advertisement -