Author |
Topic |
annas
Starting Member
36 Posts |
Posted - 2008-04-03 : 12:08:33
|
Haiii..I save number in database as varchar, but i want to call it back andconvert as double/int. Can it be done |
|
harsh_athalye
Master Smack Fu Yak Hacker
5581 Posts |
Posted - 2008-04-03 : 12:11:44
|
Yes. use CAST or CONVERT for that.Harsh AthalyeIndia."The IMPOSSIBLE is often UNTRIED" |
 |
|
annas
Starting Member
36 Posts |
Posted - 2008-04-04 : 01:12:43
|
Let say the i already convert it, but at the same time i also want tosum all data in the row. THank U |
 |
|
tkizer
Almighty SQL Goddess
38200 Posts |
Posted - 2008-04-04 : 01:16:20
|
Provide a data example to illustrate your problem.Tara KizerMicrosoft MVP for Windows Server System - SQL Serverhttp://weblogs.sqlteam.com/tarad/ |
 |
|
annas
Starting Member
36 Posts |
Posted - 2008-04-04 : 03:18:36
|
Example:Let say this represent a price table in database. I declare the Price as VarcharSo i want to convert all the data into double and also sum it allPRICE_______2.52.9934.5024.091.99 |
 |
|
harsh_athalye
Master Smack Fu Yak Hacker
5581 Posts |
Posted - 2008-04-04 : 05:18:21
|
How difficult is that?Select sum(cast(price as decimal(12,2))) as Sum_PriceFrom table Harsh AthalyeIndia."The IMPOSSIBLE is often UNTRIED" |
 |
|
annas
Starting Member
36 Posts |
Posted - 2008-04-04 : 21:52:28
|
The code does work, but i don't want to save as decimal but as double data type.I alter the code and put double. An error occur"Unable to parse query text." |
 |
|
annas
Starting Member
36 Posts |
Posted - 2008-04-04 : 21:56:33
|
Also is it possible to convert to decimal first and then to double |
 |
|
tkizer
Almighty SQL Goddess
38200 Posts |
Posted - 2008-04-04 : 21:57:00
|
Double isn't a valid SQL Server data type. Check BOL for valid data types.Tara KizerMicrosoft MVP for Windows Server System - SQL Serverhttp://weblogs.sqlteam.com/tarad/ |
 |
|
annas
Starting Member
36 Posts |
Posted - 2008-04-05 : 00:33:09
|
The problem is, event i sing a valid data type, like money or float. The result is the same |
 |
|
tkizer
Almighty SQL Goddess
38200 Posts |
Posted - 2008-04-05 : 01:42:57
|
I don't understand what you mean.Tara KizerMicrosoft MVP for Windows Server System - SQL Serverhttp://weblogs.sqlteam.com/tarad/ |
 |
|
madhivanan
Premature Yak Congratulator
22864 Posts |
Posted - 2008-04-05 : 02:19:00
|
quote: Originally posted by annas The problem is, event i sing a valid data type, like money or float. The result is the same
Then you should post expected result for the sample data you have givenMadhivananFailing to plan is Planning to fail |
 |
|
annas
Starting Member
36 Posts |
Posted - 2008-04-05 : 12:44:45
|
So what i want do is calculate some amount of price ok. Since i cannot declare as float, double or money in sql.So i use varchar instead so the float no. can be save as float. To sum the number i have to convert it into decimal and sum.But i want it to be convert back again into float. Can it be done |
 |
|
annas
Starting Member
36 Posts |
Posted - 2008-04-05 : 12:59:54
|
ok thanks everyonesome how i manage to doit. Since i building an application using vb.net and sql. When i sum it and retrieve backto vb.net then i convert i back to double. |
 |
|
|