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
 SQL Server 2000 Forums
 Transact-SQL (2000)
 casting entire columns to a different data type

Author  Topic 

minnie mouse
Starting Member

1 Post

Posted - 2006-12-06 : 23:18:37
As a beginner i am looking for a way to CAST an entire column of a data table from nvarchar datatype to Numeric datatype. So i can then perform calculations on the data , such as SUM of the column.
I believe I can use a stored procedure for this?
Any help would be appreciated.

madhivanan
Premature Yak Congratulator

22864 Posts

Posted - 2006-12-07 : 00:00:46

1 Always use proper datatype
2 Use cast(nvarcharcol as numeric(20,2))
3 Make sure that there are no alphabets and special characters in the data

Madhivanan

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

harsh_athalye
Master Smack Fu Yak Hacker

5581 Posts

Posted - 2006-12-07 : 00:02:19
You can convert to Numeric by using CAST or CONVERT functions, provided your data contains valid numeric data (no alphabets or special characters).

But my question is rather than storing as nvarchar and then converting back to numeric, why don't store in proper data type in the first place?

Harsh Athalye
India.
"Nothing is Impossible"
Go to Top of Page

madhivanan
Premature Yak Congratulator

22864 Posts

Posted - 2006-12-07 : 00:15:02
Today, you are slow Harsh

Madhivanan

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

harsh_athalye
Master Smack Fu Yak Hacker

5581 Posts

Posted - 2006-12-07 : 02:50:31
Yup!!

I think you too applied "SuperPoster Peso version 8.0.63" plug-in on your bot!

Harsh Athalye
India.
"Nothing is Impossible"
Go to Top of Page

madhivanan
Premature Yak Congratulator

22864 Posts

Posted - 2006-12-07 : 05:05:34
quote:
Originally posted by harsh_athalye

Yup!!

I think you too applied "SuperPoster Peso version 8.0.63" plug-in on your bot!

Harsh Athalye
India.
"Nothing is Impossible"


What is special on 8.0.63?

Madhivanan

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

harsh_athalye
Master Smack Fu Yak Hacker

5581 Posts

Posted - 2006-12-07 : 05:41:35
Nothing special!!

It's the latest version of "SuperPoster Peso" plug-in

Harsh Athalye
India.
"Nothing is Impossible"
Go to Top of Page

madhivanan
Premature Yak Congratulator

22864 Posts

Posted - 2006-12-07 : 09:00:36


Madhivanan

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

- Advertisement -