Skip to content

Fix bug in Example D#6784

Merged
ktoliver merged 1 commit intoMicrosoftDocs:livefrom
Mankarse:patch-1
Oct 15, 2021
Merged

Fix bug in Example D#6784
ktoliver merged 1 commit intoMicrosoftDocs:livefrom
Mankarse:patch-1

Conversation

@Mankarse
Copy link
Copy Markdown
Contributor

@Mankarse Mankarse commented Sep 6, 2021

The example pattern '%[^ 0-9A-z]%' did not match characters in the range 91-96, even though they are not numbers, letters, or spaces.
For example:
SELECT position = PATINDEX('%[^ 0-9A-z]%', 'Please^ensure the door is locked!');
returns 33, but it should return 7.
With the proposed update, it works correctly.

The example pattern '%[^ 0-9A-z]%' did not match characters in the range 91-96, even though they are not numbers, letters, or spaces.
For example:
SELECT position = PATINDEX('%[^ 0-9A-Za-z]%', 'Please^ensure the door is locked!');
returns 33, but it should return 7.
With the proposed update, it works correctly.
@PRMerger20
Copy link
Copy Markdown
Contributor

@Mankarse : Thanks for your contribution! The author(s) have been notified to review your proposed change.

@julieMSFT
Copy link
Copy Markdown
Contributor

@Mankarse What collation are you using. I am using SQL_Latin1_General_CP1_CI_AS. and the code works as expected.
image

@Mankarse
Copy link
Copy Markdown
Contributor Author

I have tried a variety of different collations. It is true that the original code works correctly in SQL_Latin1_General_CP1_CI_AS, but the only version that works correctly in every Latin collation that I tried is the version that I suggested.

SELECT
    [[^ 0-9A-z]] SQL_Latin1_General_CP1_CI_AS] = PATINDEX('%[^ 0-9A-z]%' COLLATE SQL_Latin1_General_CP1_CI_AS, 'Please^ensure the door is locked!') --7
   ,[[^ 0-9A-z]] SQL_Latin1_General_CP1_CS_AS] = PATINDEX('%[^ 0-9A-z]%' COLLATE SQL_Latin1_General_CP1_CS_AS, 'Please^ensure the door is locked!') --7
   ,[[^ 0-9A-z]] Latin1_General_CI_AS]         = PATINDEX('%[^ 0-9A-z]%' COLLATE Latin1_General_CI_AS        , 'Please^ensure the door is locked!') --7
   ,[[^ 0-9A-z]] Latin1_General_CS_AS]         = PATINDEX('%[^ 0-9A-z]%' COLLATE Latin1_General_CS_AS        , 'Please^ensure the door is locked!') --4
   ,[[^ 0-9A-z]] Latin1_General_100_CI_AS]     = PATINDEX('%[^ 0-9A-z]%' COLLATE Latin1_General_100_CI_AS    , 'Please^ensure the door is locked!') --7
   ,[[^ 0-9A-z]] Latin1_General_100_CS_AS]     = PATINDEX('%[^ 0-9A-z]%' COLLATE Latin1_General_100_CS_AS    , 'Please^ensure the door is locked!') --4
   ,[[^ 0-9A-z]] Latin1_General_100_BIN2]      = PATINDEX('%[^ 0-9A-z]%' COLLATE Latin1_General_100_BIN2     , 'Please^ensure the door is locked!') --33
;

SELECT
    [[^ 0-9a-Z]] SQL_Latin1_General_CP1_CI_AS] = PATINDEX('%[^ 0-9a-Z]%' COLLATE SQL_Latin1_General_CP1_CI_AS, 'Please^ensure the door is locked!')--7
   ,[[^ 0-9a-Z]] SQL_Latin1_General_CP1_CS_AS] = PATINDEX('%[^ 0-9a-Z]%' COLLATE SQL_Latin1_General_CP1_CS_AS, 'Please^ensure the door is locked!')--7
   ,[[^ 0-9a-Z]] Latin1_General_CI_AS]         = PATINDEX('%[^ 0-9a-A]%' COLLATE Latin1_General_CI_AS        , 'Please^ensure the door is locked!')--1
   ,[[^ 0-9a-Z]] Latin1_General_CS_AS]         = PATINDEX('%[^ 0-9a-Z]%' COLLATE Latin1_General_CS_AS        , 'Please^ensure the door is locked!')--7
   ,[[^ 0-9a-Z]] Latin1_General_100_CI_AS]     = PATINDEX('%[^ 0-9a-Z]%' COLLATE Latin1_General_100_CI_AS    , 'Please^ensure the door is locked!')--7
   ,[[^ 0-9a-Z]] Latin1_General_100_CS_AS]     = PATINDEX('%[^ 0-9a-Z]%' COLLATE Latin1_General_100_CS_AS    , 'Please^ensure the door is locked!')--7
   ,[[^ 0-9a-Z]] Latin1_General_100_BIN2]      = PATINDEX('%[^ 0-9a-Z]%' COLLATE Latin1_General_100_BIN2     , 'Please^ensure the door is locked!')--1
;

SELECT
    [[^ 0-9a-zA-Z]] SQL_Latin1_General_CP1_CI_AS] = PATINDEX('%[^ 0-9a-zA-Z]%' COLLATE SQL_Latin1_General_CP1_CI_AS, 'Please^ensure the door is locked!')--7
   ,[[^ 0-9a-zA-Z]] SQL_Latin1_General_CP1_CS_AS] = PATINDEX('%[^ 0-9a-zA-Z]%' COLLATE SQL_Latin1_General_CP1_CS_AS, 'Please^ensure the door is locked!')--7
   ,[[^ 0-9a-zA-Z]] Latin1_General_CI_AS]         = PATINDEX('%[^ 0-9a-zA-Z]%' COLLATE Latin1_General_CI_AS        , 'Please^ensure the door is locked!')--7
   ,[[^ 0-9a-aA-Z]] Latin1_General_CS_AS]         = PATINDEX('%[^ 0-9a-zA-Z]%' COLLATE Latin1_General_CS_AS        , 'Please^ensure the door is locked!')--7
   ,[[^ 0-9a-zA-Z]] Latin1_General_100_CI_AS]     = PATINDEX('%[^ 0-9a-zA-Z]%' COLLATE Latin1_General_100_CI_AS    , 'Please^ensure the door is locked!')--7
   ,[[^ 0-9a-zA-Z]] Latin1_General_100_CS_AS]     = PATINDEX('%[^ 0-9a-zA-Z]%' COLLATE Latin1_General_100_CS_AS    , 'Please^ensure the door is locked!')--7
   ,[[^ 0-9a-zA-Z]] Latin1_General_100_BIN2]      = PATINDEX('%[^ 0-9a-zA-Z]%' COLLATE Latin1_General_100_BIN2     , 'Please^ensure the door is locked!')--7
;

@julieMSFT
Copy link
Copy Markdown
Contributor

@Mankarse Thank you for the detailed response and for your contribution to Microsoft Docs.

@julieMSFT
Copy link
Copy Markdown
Contributor

#sign-off

@ktoliver ktoliver merged commit b5f637d into MicrosoftDocs:live Oct 15, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

7 participants