-- 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'
This page was last updated on May 01, 2006 04:28 PM.