Re: Pattern Matching



On Jan 6, 9:54 pm, Subind <subind...@xxxxxxxxx> wrote:
Hi,
How to match a string containing only numbers? The below method
doesn't works.
Please help.

declare @s varchar(30)
select @s="123"

if(@s like '[0-9]')
   print "This string contains only numbers"
else
   print "This string contains special characters"

Thanks,

Hi

I think it is easier to check for presence of unwanted characters in
the string, for example:

declare @s varchar(30)
select @s="123"
if(@s not like '%[A-z]%')
print "This string contains only numbers"
else
print "This string contains special characters"
go

You may want to add additional unwanted characters to the list. In
addition, you may just try to convert the string to int with convert
function, but I found it difficult to handle the possible error
message properly in T-SQL.

Hope it helps
Leonid Gvirtz
.



Relevant Pages

  • Re: UnRAROCX.ocx and unrar.dll
    ... FileName As String * 260 ... Private Type RAROpenArchiveData ... Private Declare Function RARCloseArchive Lib "unrar.dll" (ByVal hArcData As ...
    (microsoft.public.dotnet.languages.vb)
  • Re: Problem with passing parameter
    ... > 1) Your declare for WriteFile is incorrect. ... Since you're using strings you'd alias this API with an "A". ... > 2) You can *not* pass a variant, even if it's type is string, to an API ...
    (microsoft.public.vb.general.discussion)
  • Re: Problem with passing parameter
    ... Your declare for WriteFile is incorrect. ... Since you're using strings you'd alias this API with an "A". ... You can *not* pass a variant, even if it's type is string, to an API ... Public Sub WriteData ...
    (microsoft.public.vb.general.discussion)
  • Re: 2 Gig (roughly) file size limit -- NOT DBF RELATED
    ... declare Integer OpenFile in Win32API String, String, Integer ... > though FREAD() can read bytes from the file. ...
    (microsoft.public.fox.programmer.exchange)
  • can openxml write multiple fields - 1 row?
    ... I got an xml routine from the Sql Server NG where I can ... delimiters in the string. ... Declare @iDoc Int ...
    (microsoft.public.sqlserver.xml)