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 2000 Forums
 SQL Server Development (2000)
 isnumeric() function
 New Topic  Reply to Topic
 Printer Friendly
Author Previous Topic Topic Next Topic  

db_sysadmin
Starting Member

27 Posts

Posted - 01/06/2006 :  08:58:38  Show Profile  Reply with Quote
Hey Guys,

Is there a way to do something like this:

SELECT * FROM Table WHERE isnumeric(varcharfield)

What I mean is to select rows that are numeric on a varchar type column.

Thanks in advance...

nr
SQLTeam MVY

United Kingdom
12543 Posts

Posted - 01/06/2006 :  09:01:10  Show Profile  Visit nr's Homepage  Reply with Quote
depends what you mean by numeric.
SELECT * FROM Table WHERE isnumeric(varcharfield) = 1
will allow through things like 1e2 which can be converted to a numeric datatype.

You might want
where patindex('%[^0-9]%',varcharfield) = 0
which will give those which have only numeric digits.


==========================================
Cursors are useful if you don't know sql.
DTS can be used in a similar way.
Beer is not cold and it isn't fizzy.
Go to Top of Page

madhivanan
Premature Yak Congratulator

India
22761 Posts

Posted - 01/06/2006 :  09:05:59  Show Profile  Send madhivanan a Yahoo! Message  Reply with Quote
Read more about Isnumeric
http://aspfaq.com/show.asp?id=2390

Madhivanan

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

db_sysadmin
Starting Member

27 Posts

Posted - 01/06/2006 :  09:10:32  Show Profile  Reply with Quote
Thanks for your reply...What I want to do is...convert a nvarchar field to numeric...so I want to see which records contain numeric values to correct the ones that are not...
I couln't do it yet...I keep getting this:
- Unable to modify table.
ODBC error: [Microsoft][ODBC SQL Server Driver][SQL Server]Error converting data type nvarchar to numeric.

seems to be a problem with Null and blank ocurrences...

Thanks a lot!!!
Go to Top of Page

madhivanan
Premature Yak Congratulator

India
22761 Posts

Posted - 01/06/2006 :  09:21:08  Show Profile  Send madhivanan a Yahoo! Message  Reply with Quote
Did you try nr's query?

Madhivanan

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

db_sysadmin
Starting Member

27 Posts

Posted - 01/06/2006 :  09:27:53  Show Profile  Reply with Quote
I did, thank you both guys!,

I worked it out...it was a problem convertin an empty string to NULL.

Thansk...
Go to Top of Page

Kristen
Test

United Kingdom
22415 Posts

Posted - 01/06/2006 :  09:35:50  Show Profile  Reply with Quote
Seems like you are all done ... but in case you've got more to do! :

I've got a function that converts varchar to int - and returns NULL for failures - which is a bit more robust than IsNumeric()

http://www.sqlteam.com/forums/topic.asp?TOPIC_ID=59049

Kristen
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.08 seconds. Powered By: Snitz Forums 2000