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 |
|
velliraj
Yak Posting Veteran
59 Posts |
Posted - 2010-07-19 : 08:19:20
|
| While working on one Data type conversion activity in SQL Server, we came across one scenario where we need to take value from one column having data type as Varchar, and use that column in function (where Datatype for that column would be Float for Arithmatic calculation) and thereafter populate the calculated value again back to that column with datatype varchar.So the case is Varchar to Float and again Float to Varchar conversion for that specific column.The Decimal places can not be bounded as per the business constraints. therefore we cant use decimal conversion. below example will demonstrate the scenario.Is there any way to get the accurate values back in to the column after all the calculation. Please suggest.declare @value varchar(100)set @value= '4567623.234455'declare @newValue FloatSet @NewValue= @Valueselect @NewValue as ValueASFloatselect convert(varchar(255),@NewValue) as ValueASVarcharselect Cast( @NewValue as Decimal(20,9)) as ValueASDecimalPlease any one help.... |
|
|
senthil_nagore
Master Smack Fu Yak Hacker
1007 Posts |
Posted - 2010-07-19 : 08:48:10
|
| Try thisselect @NewValue as ValueASFloatselect @NewValue+'' as ValueASVarcharselect Cast( @NewValue as Decimal(20,6)) as ValueASDecimalSenthil.C------------------------------------------------------[Microsoft][ODBC SQL Server Driver]Operation canceledhttp://senthilnagore.blogspot.com/ |
 |
|
|
madhivanan
Premature Yak Congratulator
22864 Posts |
Posted - 2010-07-19 : 08:50:46
|
| declare @value varchar(100)set @value= '4567623.234455'declare @newValue float-- decimal(16,8)Set @NewValue= @Valueselect @NewValue as ValueASFloatselect convert(varchar(255),@NewValue) as ValueASVarcharselect Cast( @NewValue as Decimal(20,6)) as ValueASDecimalMadhivananFailing to plan is Planning to fail |
 |
|
|
velliraj
Yak Posting Veteran
59 Posts |
Posted - 2010-07-19 : 09:35:06
|
| Hi madhi,Thanks for your inputs.I need to get the output, same as float value even after storing in the varchar column. using decimal function is restricting decimal points.we dont want to use the decimal function. |
 |
|
|
|
|
|