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.
| Author |
Topic |
|
madscientist
Starting Member
30 Posts |
Posted - 2008-02-06 : 11:54:03
|
| Hello everyone,Can anyone please help me with a problem I'm having difficulty figuring out. I have a field named [FINAL_RATE] which is a float with values including 0, 0.34, 0.038, etc.I would like to move the decimal over to the right in all cases possible whether there is 0, 1, 2, 3, etc. decimal places.Thank you for the help. |
|
|
visakh16
Very Important crosS Applying yaK Herder
52326 Posts |
Posted - 2008-02-06 : 12:08:23
|
| try:-UPDATE TableSET FINAL_RATE=FINAL_RATE * POWER(10,LEN(LEFT(REVERSE(CAST(FINAL_RATE as varchar(10))),CHARINDEX('.',REVERSE(CAST(FINAL_RATE as varchar(10))))-1))) |
 |
|
|
madscientist
Starting Member
30 Posts |
Posted - 2008-02-06 : 12:46:11
|
| thank you for your response visakh16but when i execute the query i get an error message:"Invalid length parameter passed to the SUBSTRING function." |
 |
|
|
visakh16
Very Important crosS Applying yaK Herder
52326 Posts |
Posted - 2008-02-06 : 12:56:57
|
| change it like this & try:-UPDATE TableSET FINAL_RATE=FINAL_RATE * POWER(10,LEN(LEFT(REVERSE(CAST(FINAL_RATE as varchar(10))),CASE WHEN CHARINDEX('.',REVERSE(CAST(FINAL_RATE as varchar(10))))>0 THEN CHARINDEX('.',REVERSE(CAST(FINAL_RATE as varchar(10)))) ELSE 1 END -1))) |
 |
|
|
madscientist
Starting Member
30 Posts |
Posted - 2008-02-06 : 13:07:56
|
| It worked. Thank you very much visakh16 for all of your help! |
 |
|
|
visakh16
Very Important crosS Applying yaK Herder
52326 Posts |
Posted - 2008-02-06 : 13:15:42
|
| You are welcome :) |
 |
|
|
madhivanan
Premature Yak Congratulator
22864 Posts |
Posted - 2008-02-07 : 07:33:31
|
| I am not sure if this worksSelect replace(FINAL_RATE,'.','') as FINAL_RATE from yourtableMadhivananFailing to plan is Planning to fail |
 |
|
|
|
|
|
|
|