Regular Expressions and SQL

Results 1 to 2 of 2

Thread: Regular Expressions and SQL

  1. #1
    Join Date
    Dec 1969

    Default Regular Expressions and SQL

    SQL Server 2K<BR><BR>I&#039;d like to assemble a query that checks a field for BOTH alpha numerics - in other words<BR><BR>a1b2c3 would satisfy the query,<BR>abc or 123 would NOT<BR><BR>Since SQL has no reg exp engine, and ISNUMERIC in this case would always return false, anyone have any idea how I can approach this? I&#039;m at a wall...<BR><BR>Thanks <BR>TBB

  2. #2
    Join Date
    Dec 1969

    Default Write an UDF

    create function verifyAlpha (@stringVerify varchar(30))<BR>returns int as<BR>begin<BR> declare @i int<BR> declare @c int<BR> set @i = 1<BR> while @i &#060;= char_length (@stringVerify)<BR> begin<BR> set @c = ascii(substring(@stringVeify,i,1) <BR> if @c not between ascii(&#039;0&#039;) and ascii(&#039;9)<BR> and @c not between ascii(&#039;a&#039;) and ascii(&#039;z&#039;) return 1<BR> set @i = @i + 1<BR> end <BR> return 0

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts