SQL Server Forums
Profile | Register | Active Topics | Members | Search | Forum FAQ
 
Register Now and get your question answered!
Username:
Password:
Save Password
Forgot your Password?

 All Forums
 SQL Server 2005 Forums
 .NET Inside SQL Server (2005)
 Converting from varchar to double or integer
 New Topic  Reply to Topic
 Printer Friendly
Author Previous Topic Topic Next Topic  

annas
Starting Member

36 Posts

Posted - 04/03/2008 :  12:08:33  Show Profile  Send annas a Yahoo! Message  Reply with Quote
Haiii..

I save number in database as varchar, but i want to call it back and
convert as double/int. Can it be done

harsh_athalye
Flowing Fount of Yak Knowledge

India
5509 Posts

Posted - 04/03/2008 :  12:11:44  Show Profile  Visit harsh_athalye's Homepage  Click to see harsh_athalye's MSN Messenger address  Send harsh_athalye a Yahoo! Message  Reply with Quote
Yes. use CAST or CONVERT for that.

Harsh Athalye
India.
"The IMPOSSIBLE is often UNTRIED"
Go to Top of Page

annas
Starting Member

36 Posts

Posted - 04/04/2008 :  01:12:43  Show Profile  Send annas a Yahoo! Message  Reply with Quote
Let say the i already convert it, but at the same time i also want to
sum all data in the row.

THank U
Go to Top of Page

tkizer
Almighty SQL Goddess

USA
36851 Posts

Posted - 04/04/2008 :  01:16:20  Show Profile  Visit tkizer's Homepage  Reply with Quote
Provide a data example to illustrate your problem.

Tara Kizer
Microsoft MVP for Windows Server System - SQL Server
http://weblogs.sqlteam.com/tarad/
Go to Top of Page

annas
Starting Member

36 Posts

Posted - 04/04/2008 :  03:18:36  Show Profile  Send annas a Yahoo! Message  Reply with Quote
Example:
Let say this represent a price table in database. I declare the Price as Varchar
So i want to convert all the data into double and also sum it all

PRICE
_______
2.5
2.99
34.50
24.09
1.99

Go to Top of Page

harsh_athalye
Flowing Fount of Yak Knowledge

India
5509 Posts

Posted - 04/04/2008 :  05:18:21  Show Profile  Visit harsh_athalye's Homepage  Click to see harsh_athalye's MSN Messenger address  Send harsh_athalye a Yahoo! Message  Reply with Quote
How difficult is that?

Select sum(cast(price as decimal(12,2))) as Sum_Price
From table


Harsh Athalye
India.
"The IMPOSSIBLE is often UNTRIED"
Go to Top of Page

annas
Starting Member

36 Posts

Posted - 04/04/2008 :  21:52:28  Show Profile  Send annas a Yahoo! Message  Reply with Quote
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."
Go to Top of Page

annas
Starting Member

36 Posts

Posted - 04/04/2008 :  21:56:33  Show Profile  Send annas a Yahoo! Message  Reply with Quote
Also is it possible to convert to decimal first and then to double
Go to Top of Page

tkizer
Almighty SQL Goddess

USA
36851 Posts

Posted - 04/04/2008 :  21:57:00  Show Profile  Visit tkizer's Homepage  Reply with Quote
Double isn't a valid SQL Server data type. Check BOL for valid data types.

Tara Kizer
Microsoft MVP for Windows Server System - SQL Server
http://weblogs.sqlteam.com/tarad/
Go to Top of Page

annas
Starting Member

36 Posts

Posted - 04/05/2008 :  00:33:09  Show Profile  Send annas a Yahoo! Message  Reply with Quote
The problem is, event i sing a valid data type, like money or float. The result is the same
Go to Top of Page

tkizer
Almighty SQL Goddess

USA
36851 Posts

Posted - 04/05/2008 :  01:42:57  Show Profile  Visit tkizer's Homepage  Reply with Quote
I don't understand what you mean.

Tara Kizer
Microsoft MVP for Windows Server System - SQL Server
http://weblogs.sqlteam.com/tarad/
Go to Top of Page

madhivanan
Premature Yak Congratulator

India
22755 Posts

Posted - 04/05/2008 :  02:19:00  Show Profile  Send madhivanan a Yahoo! Message  Reply with Quote
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 given

Madhivanan

Failing to plan is Planning to fail
Go to Top of Page

annas
Starting Member

36 Posts

Posted - 04/05/2008 :  12:44:45  Show Profile  Send annas a Yahoo! Message  Reply with Quote
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
Go to Top of Page

annas
Starting Member

36 Posts

Posted - 04/05/2008 :  12:59:54  Show Profile  Send annas a Yahoo! Message  Reply with Quote
ok thanks everyone
some how i manage to doit. Since i building an application using vb.net and sql. When i sum it and retrieve back
to vb.net then i convert i back to double.
Go to Top of Page
  Previous Topic Topic Next Topic  
 New Topic  Reply to Topic
 Printer Friendly
Jump To:
SQL Server Forums © 2000-2009 SQLTeam Publishing, LLC Go To Top Of Page
This page was generated in 0.12 seconds. Powered By: Snitz Forums 2000