472,958 Members | 1,943 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 472,958 software developers and data experts.

SIMPLE command to convert string to number? Not CAST or CONVERT.

Dear Experts,

Ok, I hate to ask such a seemingly dumb question, but I've
already spent far too much time on this. More that I
would care to admit.

In Sql server, how do I simply change a character into a number??????

In Oracle, it is:

select to_number(20.55)
from dual

TO_NUMBER(20.55)
----------------
20.55

And we are on with our lives.
In sql server, using the Northwinds database:

SELECT
r.regionid,
STR(r.regionid,7,2) as a_string,
CONVERT(numeric, STR(r.regionid,7,2)) as a_number,
cast ( STR(r.regionid) as int ) as cast_to_number
FROM REGION R

1 1.00 1 1
2 2.00 2 2
3 3.00 3 3
4 4.00 4 4


SELECT
r.regionid,
STR(r.regionid,7,2) as a_string,
CONVERT(numeric, STR(r.regionid,7,2) ) as a_number,
cast (STR(r.regionid,7,2) as numeric ) as cast_to_number
FROM REGION R

1 1.00 1 1
2 2.00 2 2
3 3.00 3 3
4 4.00 4 4

Str converts from number to string in one motion.

Isn't there a simple function in Sql Server to convert
from string to number?

What is the secret?

Thanks

Aug 15 '06 #1
4 118723
db*****@yahoo.com wrote:
Dear Experts,

Ok, I hate to ask such a seemingly dumb question, but I've
already spent far too much time on this. More that I
would care to admit.

In Sql server, how do I simply change a character into a number??????

In Oracle, it is:

select to_number(20.55)
from dual

TO_NUMBER(20.55)
----------------
20.55

And we are on with our lives.
In sql server, using the Northwinds database:

SELECT
r.regionid,
STR(r.regionid,7,2) as a_string,
CONVERT(numeric, STR(r.regionid,7,2)) as a_number,
cast ( STR(r.regionid) as int ) as cast_to_number
FROM REGION R

1 1.00 1 1
2 2.00 2 2
3 3.00 3 3
4 4.00 4 4


SELECT
r.regionid,
STR(r.regionid,7,2) as a_string,
CONVERT(numeric, STR(r.regionid,7,2) ) as a_number,
cast (STR(r.regionid,7,2) as numeric ) as cast_to_number
FROM REGION R

1 1.00 1 1
2 2.00 2 2
3 3.00 3 3
4 4.00 4 4

Str converts from number to string in one motion.

Isn't there a simple function in Sql Server to convert
from string to number?

What is the secret?

Thanks
I don't really understand your problem. CAST does what you want and has
the advantage of being Standard SQL (unlike TO_NUMBER). STR does
something different and isn't needed in this case.

--
David Portas, SQL Server MVP

Whenever possible please post enough code to reproduce your problem.
Including CREATE TABLE and INSERT statements usually helps.
State what version of SQL Server you are using and specify the content
of any error messages.

SQL Server Books Online:
http://msdn2.microsoft.com/library/m...S,SQL.90).aspx
--

Aug 15 '06 #2
Hmm. The question remains the same. (Not, why do I want to do that,
or, what's wrong with what you already have? Or, you shouldn't do
that.)

I want a SIMPLE sql server function like to_number(), or str()
To convert a string to a number.

Does a simple function exist in sql server to do the conversion?
What is the secret?

Thanks

David Portas wrote:
db*****@yahoo.com wrote:
Dear Experts,

Ok, I hate to ask such a seemingly dumb question, but I've
already spent far too much time on this. More that I
would care to admit.

In Sql server, how do I simply change a character into a number??????

In Oracle, it is:

select to_number(20.55)
from dual

TO_NUMBER(20.55)
----------------
20.55

And we are on with our lives.
In sql server, using the Northwinds database:

SELECT
r.regionid,
STR(r.regionid,7,2) as a_string,
CONVERT(numeric, STR(r.regionid,7,2)) as a_number,
cast ( STR(r.regionid) as int ) as cast_to_number
FROM REGION R

1 1.00 1 1
2 2.00 2 2
3 3.00 3 3
4 4.00 4 4


SELECT
r.regionid,
STR(r.regionid,7,2) as a_string,
CONVERT(numeric, STR(r.regionid,7,2) ) as a_number,
cast (STR(r.regionid,7,2) as numeric ) as cast_to_number
FROM REGION R

1 1.00 1 1
2 2.00 2 2
3 3.00 3 3
4 4.00 4 4

Str converts from number to string in one motion.

Isn't there a simple function in Sql Server to convert
from string to number?

What is the secret?

Thanks

I don't really understand your problem. CAST does what you want and has
the advantage of being Standard SQL (unlike TO_NUMBER). STR does
something different and isn't needed in this case.

--
David Portas, SQL Server MVP

Whenever possible please post enough code to reproduce your problem.
Including CREATE TABLE and INSERT statements usually helps.
State what version of SQL Server you are using and specify the content
of any error messages.

SQL Server Books Online:
http://msdn2.microsoft.com/library/m...S,SQL.90).aspx
--
Aug 15 '06 #3
Yes, there is a simple function. It is called CAST(). It is has the
advantage of being completely ANSI SQL compliant. And it is easy to use.

Of course, you could make your own FUNCTION if CAST() is too complex or
difficult to use.

I don't get the repeated question. It was asked and answered.

--
Arnie Rowland, Ph.D.
Westwood Consulting, Inc

Most good judgment comes from experience.
Most experience comes from bad judgment.
- Anonymous
<db*****@yahoo.comwrote in message
news:11**********************@h48g2000cwc.googlegr oups.com...
Hmm. The question remains the same. (Not, why do I want to do that,
or, what's wrong with what you already have? Or, you shouldn't do
that.)

I want a SIMPLE sql server function like to_number(), or str()
To convert a string to a number.

Does a simple function exist in sql server to do the conversion?
What is the secret?

Thanks

David Portas wrote:
>db*****@yahoo.com wrote:
Dear Experts,

Ok, I hate to ask such a seemingly dumb question, but I've
already spent far too much time on this. More that I
would care to admit.

In Sql server, how do I simply change a character into a number??????

In Oracle, it is:

select to_number(20.55)
from dual

TO_NUMBER(20.55)
----------------
20.55

And we are on with our lives.
In sql server, using the Northwinds database:

SELECT
r.regionid,
STR(r.regionid,7,2) as a_string,
CONVERT(numeric, STR(r.regionid,7,2)) as a_number,
cast ( STR(r.regionid) as int ) as cast_to_number
FROM REGION R

1 1.00 1 1
2 2.00 2 2
3 3.00 3 3
4 4.00 4 4


SELECT
r.regionid,
STR(r.regionid,7,2) as a_string,
CONVERT(numeric, STR(r.regionid,7,2) ) as a_number,
cast (STR(r.regionid,7,2) as numeric ) as cast_to_number
FROM REGION R

1 1.00 1 1
2 2.00 2 2
3 3.00 3 3
4 4.00 4 4

Str converts from number to string in one motion.

Isn't there a simple function in Sql Server to convert
from string to number?

What is the secret?

Thanks

I don't really understand your problem. CAST does what you want and has
the advantage of being Standard SQL (unlike TO_NUMBER). STR does
something different and isn't needed in this case.

--
David Portas, SQL Server MVP

Whenever possible please post enough code to reproduce your problem.
Including CREATE TABLE and INSERT statements usually helps.
State what version of SQL Server you are using and specify the content
of any error messages.

SQL Server Books Online:
http://msdn2.microsoft.com/library/m...S,SQL.90).aspx
--

Aug 16 '06 #4
The ANSI/ISO international standard for the SQL language
does not provide the function you want. Oracle chose to add
a proprietary nonstandard function for this (which seems not
to allow you to specify the specific number type, and there are
many), and SQL Server uses the ANSI/ISO CAST function and
requires a type.

SELECT CAST('20.55' AS DECIMAL(4,2))

You can (if you know the consequences) use implicit conversion:

SELECT 100.00*'20.55'
SELECT 10000.0000*'20.55'
SELECT 1E0*'20.55'

If you aren't happy with what SQL offers as a language, there are
plenty of other languages in the world of computing from which
you can choose another.

Steve Kass
Drew University

<db*****@yahoo.comwrote in message news:11**********************@h48g2000cwc.googlegr oups.com...
Hmm. The question remains the same. (Not, why do I want to do that,
or, what's wrong with what you already have? Or, you shouldn't do
that.)

I want a SIMPLE sql server function like to_number(), or str()
To convert a string to a number.

Does a simple function exist in sql server to do the conversion?
What is the secret?

Thanks

David Portas wrote:
>db*****@yahoo.com wrote:
Dear Experts,

Ok, I hate to ask such a seemingly dumb question, but I've
already spent far too much time on this. More that I
would care to admit.

In Sql server, how do I simply change a character into a number??????

In Oracle, it is:

select to_number(20.55)
from dual

TO_NUMBER(20.55)
----------------
20.55

And we are on with our lives.
In sql server, using the Northwinds database:

SELECT
r.regionid,
STR(r.regionid,7,2) as a_string,
CONVERT(numeric, STR(r.regionid,7,2)) as a_number,
cast ( STR(r.regionid) as int ) as cast_to_number
FROM REGION R

1 1.00 1 1
2 2.00 2 2
3 3.00 3 3
4 4.00 4 4


SELECT
r.regionid,
STR(r.regionid,7,2) as a_string,
CONVERT(numeric, STR(r.regionid,7,2) ) as a_number,
cast (STR(r.regionid,7,2) as numeric ) as cast_to_number
FROM REGION R

1 1.00 1 1
2 2.00 2 2
3 3.00 3 3
4 4.00 4 4

Str converts from number to string in one motion.

Isn't there a simple function in Sql Server to convert
from string to number?

What is the secret?

Thanks

I don't really understand your problem. CAST does what you want and has
the advantage of being Standard SQL (unlike TO_NUMBER). STR does
something different and isn't needed in this case.

--
David Portas, SQL Server MVP

Whenever possible please post enough code to reproduce your problem.
Including CREATE TABLE and INSERT statements usually helps.
State what version of SQL Server you are using and specify the content
of any error messages.

SQL Server Books Online:
http://msdn2.microsoft.com/library/m...S,SQL.90).aspx
--

Aug 16 '06 #5

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

4
by: cindy liu | last post by:
Hi, In .Net, how to convert a string to a double? Thanks in advance! Cindy
11
by: jguilford | last post by:
I have created a SQL Stored Procedure that uses a Case statement to determine the Order By. For one of the Case statements I am trying to turn a Char field into Datetime in for the Order By,...
7
by: whatluo | last post by:
Hi, all I'm now working on a program which will convert dec number to hex and oct and bin respectively, I've checked the clc but with no luck, so can anybody give me a hit how to make this done...
6
by: Picho | last post by:
Hi group. This must have come up a few times before but I found no specific resources regarding this. the problem is simple: convert the number 55 to the string "Fifty five" (obviously with...
19
by: VK | last post by:
http://groups.google.com/group/comp.lang.javascript/browse_frm/thread/ b495b4898808fde0> is more than one month old - this may pose problem for posting over some news servers. This is why I'm...
11
by: davidj411 | last post by:
i am parsing a cell phone bill to get a list of all numbers and the total talktime spend on each number. i already have a unique list of the phone numbers. now i must go through the list of...
2
by: FAQ server | last post by:
----------------------------------------------------------------------- FAQ Topic - How do I convert a Number into a String with exactly 2 decimal places?...
4
subedimite
by: subedimite | last post by:
Here I am with another question being a very new VBA user. I have this scenario to work with: I would think this is fairly common routine of work for VBA. I have a string of hex contents as...
2
by: DJRhino | last post by:
Was curious if anyone else was having this same issue or not.... I was just Up/Down graded to windows 11 and now my access combo boxes are not acting right. With win 10 I could start typing...
2
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 4 Oct 2023 starting at 18:00 UK time (6PM UTC+1) and finishing at about 19:15 (7.15PM) The start time is equivalent to 19:00 (7PM) in Central...
0
by: Aliciasmith | last post by:
In an age dominated by smartphones, having a mobile app for your business is no longer an option; it's a necessity. Whether you're a startup or an established enterprise, finding the right mobile app...
0
tracyyun
by: tracyyun | last post by:
Hello everyone, I have a question and would like some advice on network connectivity. I have one computer connected to my router via WiFi, but I have two other computers that I want to be able to...
2
by: giovanniandrean | last post by:
The energy model is structured as follows and uses excel sheets to give input data: 1-Utility.py contains all the functions needed to calculate the variables and other minor things (mentions...
3
NeoPa
by: NeoPa | last post by:
Introduction For this article I'll be using a very simple database which has Form (clsForm) & Report (clsReport) classes that simply handle making the calling Form invisible until the Form, or all...
1
by: Teri B | last post by:
Hi, I have created a sub-form Roles. In my course form the user selects the roles assigned to the course. 0ne-to-many. One course many roles. Then I created a report based on the Course form and...
0
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 1 Nov 2023 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM) Please note that the UK and Europe revert to winter time on...
3
by: nia12 | last post by:
Hi there, I am very new to Access so apologies if any of this is obvious/not clear. I am creating a data collection tool for health care employees to complete. It consists of a number of...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.