Atlanta Custom Software Development 

 
   Search        Code/Page
 

User Login
Email

Password

 

Forgot the Password?
Services
» Web Development
» Maintenance
» Data Integration/BI
» Information Management
Programming
  Database
Automation
OS/Networking
Graphics
Links
Tools
» Regular Expr Tester
» Free Tools

Check a string for numeric digits only

Total Hit ( 1806)

Rate this article:     Poor     Excellent 

 Submit Your Question/Comment about this article

Rating


 


The ISNUMERIC function in SQL60/65/70 checks for decimal & integer values. Hence characters like D, E are valid float representations & similarly ','. This is a simple logic that can check only for numeric digits without using a loop of any kind.

Click here to copy the following block
-- The numbers are hard-coded in the SELECT below but
-- use a NUMBERS table instead. This table can also be
-- used to solve several other problems quite easily.
declare @c varchar(10)
select @c = '12' + char(9)
if exists(select * from
       (select 1 as digit union all select 2 union all
           select 3 union all select 4 union all
           select 5 union all select 6 union all
           select 7 union all select 8 union all
           select 9 union all select 10) as n
       where ascii(substring(@c, digit, 1 )) not between 48 and 57 )
   print 'No'
else
   print 'Yes'

-- Or to check for unsigned integers alone
if patindex( '%[^0-9]%' , @c ) > 0
   print 'No'
else
   print 'Yes'


Submitted By : Nayan Patel  (Member Since : 5/26/2004 12:23:06 PM)

Job Description : He is the moderator of this site and currently working as an independent consultant. He works with VB.net/ASP.net, SQL Server and other MS technologies. He is MCSD.net, MCDBA and MCSE. In his free time he likes to watch funny movies and doing oil painting.
View all (893) submissions by this author  (Birth Date : 7/14/1981 )


Home   |  Comment   |  Contact Us   |  Privacy Policy   |  Terms & Conditions   |  BlogsZappySys

© 2008 BinaryWorld LLC. All rights reserved.