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
 add a decimal point

Author  Topic 

needhelp6184
Starting Member

5 Posts

Posted - 2010-01-28 : 08:58:37
I have a bunch of numbers some 3 digits, some 4 digits, some 5 digits and i need to add a decimal after the 3rd digit for the numbers 4 and 5 digits long.

ex

456
2456
45657

i need them to look like this
456
245.6
456.57

Any help would be greatly appreciated.

webfred
Master Smack Fu Yak Hacker

8781 Posts

Posted - 2010-01-28 : 09:10:56
What is the datatype of the column that holds the values?
Should it be an update to the table or just in display?
Why do you need to do this?


No, you're never too old to Yak'n'Roll if you're too young to die.
Go to Top of Page

singularity
Posting Yak Master

153 Posts

Posted - 2010-01-28 : 09:18:34
Just out of curiosity, are these ICD9 diagnosis codes?

Maybe something like this:


select case
when len(yourfield) = 5 then left(yourfield,3) + '.' + right(yourfield,2)
when len(yourfield) = 4 then left(yourfield,3) + '.' + right(yourfield,1)
else yourfield end
from yourtable
Go to Top of Page

needhelp6184
Starting Member

5 Posts

Posted - 2010-01-28 : 10:28:38
I need to update and datatype is varchar
Go to Top of Page

needhelp6184
Starting Member

5 Posts

Posted - 2010-01-28 : 10:29:33
Singularity i think i can use what you posted and go from there. i appreciate that.
Go to Top of Page
   

- Advertisement -