Results 1 to 3 of 3

Thread: Pattern Matching Query in SQL

  1. #1

    Thread Starter
    Member
    Join Date
    Jun 2000
    Posts
    39

    Question Pattern Matching Query in SQL

    I have the following query


    SELECT PATINDEX('%[A-Z][A-X0-9][0-9]% [0-9][A-Z][A-Z]', LTRIM(RTRIM(Address))), Address, IDNumber
    FROM <MYTABLE>

    What I want to be able to do is ensure there is white space before the first part of my PATINDEX , PATINDEX('[A-Z]….

    I’ve tried

    PATINDEX(' [A-Z]….
    PATINDEX('%[A-Z]….
    PATINDEX('% [A-Z]….
    PATINDEX('[ ][A-Z]….

    What I want to ensure is that the PATINDEX doesn’t look in the middle of a word and find a match, which is what it is currently doing.

    I'm using SQL Server 2000.

    Thanks
    Last edited by Gin_bee; Jan 23rd, 2004 at 09:52 AM.

  2. #2

    Thread Starter
    Member
    Join Date
    Jun 2000
    Posts
    39
    Managed to work around problem but would be interested to know if any of you know how to solve this issue. Suspect the problem may be to do with leading whitespace.

  3. #3
    Hyperactive Member
    Join Date
    Nov 1999
    Location
    Leavenworth KS USA
    Posts
    482
    Assuming you want this kind of white space noise ( tab, CRT, vtab, page, LF, etc.)
    and those that match your lead criteria in position one, this may give you an idea.
    Code:
    patindex('%[' char(9) + char(10) + char(11)+ char(12)+ char(13) + char(32) 
      + char(160) + '][A-Z][A-X0-9][0-9]% [0-9][A-Z][A-Z]', ' ' + RTRIM(Address)), ...
    HTH.

Posting Permissions

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



Click Here to Expand Forum to Full Width