SQL Clone
SQLServerCentral is supported by Redgate
 
Log in  ::  Register  ::  Not logged in
 
 
 


PatExclude8K


PatExclude8K

Author
Message
Alan Burstein
Alan Burstein
SSC Guru
SSC Guru (59K reputation)SSC Guru (59K reputation)SSC Guru (59K reputation)SSC Guru (59K reputation)SSC Guru (59K reputation)SSC Guru (59K reputation)SSC Guru (59K reputation)SSC Guru (59K reputation)

Group: General Forum Members
Points: 59874 Visits: 9221
Comments posted to this topic are about the item PatExclude8K

-- Alan Burstein


Helpful links:

Best practices for getting help on SQLServerCentral -- Jeff Moden
How to Post Performance Problems -- Gail Shaw

Nasty fast set-based string manipulation functions:
For splitting strings try DelimitedSplit8K or DelimitedSplit8K_LEAD (SQL Server 2012+)
To split strings based on patterns try PatternSplitCM
Need to clean or transform a string? try NGrams, PatExclude8K, PatReplace8K, DigitsOnlyEE, or Translate8K

I cant stress enough the importance of switching from a sequential files mindset to set-based thinking. After you make the switch, you can spend your time tuning and optimizing your queries instead of maintaining lengthy, poor-performing code. -- Itzik Ben-Gan 2001

Matthias Kläy
Matthias Kläy
SSC Eights!
SSC Eights! (983 reputation)SSC Eights! (983 reputation)SSC Eights! (983 reputation)SSC Eights! (983 reputation)SSC Eights! (983 reputation)SSC Eights! (983 reputation)SSC Eights! (983 reputation)SSC Eights! (983 reputation)

Group: General Forum Members
Points: 983 Visits: 269
Hi Alan
Thanks for this great function. One note:

SELECT * FROM dbo.PatExclude8K('123# What?!... ', '[^a-z!?.]')



returns hat?!...
So it is case sensitive, contrary to your comment in the programmers notes. I guess this comes from the Latin1_General_BIN collation.

To get the result as expected, I can use

SELECT * FROM dbo.PatExclude8K('123# What?!... ', '[^a-zA-Z!?.]')



Matthias Kläy, http://www.kcc.ch
Alan Burstein
Alan Burstein
SSC Guru
SSC Guru (59K reputation)SSC Guru (59K reputation)SSC Guru (59K reputation)SSC Guru (59K reputation)SSC Guru (59K reputation)SSC Guru (59K reputation)SSC Guru (59K reputation)SSC Guru (59K reputation)

Group: General Forum Members
Points: 59874 Visits: 9221
Matthias Kläy (11/28/2014)
Hi Alan
Thanks for this great function. One note:

SELECT * FROM dbo.PatExclude8K('123# What?!... ', '[^a-z!?.]')



returns hat?!...
So it is case sensitive, contrary to your comment in the programmers notes. I guess this comes from the Latin1_General_BIN collation.

To get the result as expected, I can use

SELECT * FROM dbo.PatExclude8K('123# What?!... ', '[^a-zA-Z!?.]')



Matthias Kläy, http://www.kcc.ch


Thanks Matthias for your feedback and good catch! I did realize that the Latin1_General_BIN would make the function case sensitive but never updated my developer comments to reflect that change. This was my first script and I don't know what the SQLServerCentral protocol is for changing a script once it is published. I will update the developer comments once I figure out how Cool

P.S. Sorry for the late reply, it's been a busy couple weeks of moving and project wrap-up.

-- Alan Burstein


Helpful links:

Best practices for getting help on SQLServerCentral -- Jeff Moden
How to Post Performance Problems -- Gail Shaw

Nasty fast set-based string manipulation functions:
For splitting strings try DelimitedSplit8K or DelimitedSplit8K_LEAD (SQL Server 2012+)
To split strings based on patterns try PatternSplitCM
Need to clean or transform a string? try NGrams, PatExclude8K, PatReplace8K, DigitsOnlyEE, or Translate8K

I cant stress enough the importance of switching from a sequential files mindset to set-based thinking. After you make the switch, you can spend your time tuning and optimizing your queries instead of maintaining lengthy, poor-performing code. -- Itzik Ben-Gan 2001

Iwas Bornready
Iwas Bornready
SSC Guru
SSC Guru (74K reputation)SSC Guru (74K reputation)SSC Guru (74K reputation)SSC Guru (74K reputation)SSC Guru (74K reputation)SSC Guru (74K reputation)SSC Guru (74K reputation)SSC Guru (74K reputation)

Group: General Forum Members
Points: 74614 Visits: 886
Nice pattern exclusion script. Thanks.
Alan Burstein
Alan Burstein
SSC Guru
SSC Guru (59K reputation)SSC Guru (59K reputation)SSC Guru (59K reputation)SSC Guru (59K reputation)SSC Guru (59K reputation)SSC Guru (59K reputation)SSC Guru (59K reputation)SSC Guru (59K reputation)

Group: General Forum Members
Points: 59874 Visits: 9221
Thank you for the kind words Iwas

-- Alan Burstein


Helpful links:

Best practices for getting help on SQLServerCentral -- Jeff Moden
How to Post Performance Problems -- Gail Shaw

Nasty fast set-based string manipulation functions:
For splitting strings try DelimitedSplit8K or DelimitedSplit8K_LEAD (SQL Server 2012+)
To split strings based on patterns try PatternSplitCM
Need to clean or transform a string? try NGrams, PatExclude8K, PatReplace8K, DigitsOnlyEE, or Translate8K

I cant stress enough the importance of switching from a sequential files mindset to set-based thinking. After you make the switch, you can spend your time tuning and optimizing your queries instead of maintaining lengthy, poor-performing code. -- Itzik Ben-Gan 2001

Iwas Bornready
Iwas Bornready
SSC Guru
SSC Guru (74K reputation)SSC Guru (74K reputation)SSC Guru (74K reputation)SSC Guru (74K reputation)SSC Guru (74K reputation)SSC Guru (74K reputation)SSC Guru (74K reputation)SSC Guru (74K reputation)

Group: General Forum Members
Points: 74614 Visits: 886
Good script, thank you.
Alan Burstein
Alan Burstein
SSC Guru
SSC Guru (59K reputation)SSC Guru (59K reputation)SSC Guru (59K reputation)SSC Guru (59K reputation)SSC Guru (59K reputation)SSC Guru (59K reputation)SSC Guru (59K reputation)SSC Guru (59K reputation)

Group: General Forum Members
Points: 59874 Visits: 9221
Iwas Bornready (6/8/2015)
Good script, thank you.


Thanks sir!

-- Alan Burstein


Helpful links:

Best practices for getting help on SQLServerCentral -- Jeff Moden
How to Post Performance Problems -- Gail Shaw

Nasty fast set-based string manipulation functions:
For splitting strings try DelimitedSplit8K or DelimitedSplit8K_LEAD (SQL Server 2012+)
To split strings based on patterns try PatternSplitCM
Need to clean or transform a string? try NGrams, PatExclude8K, PatReplace8K, DigitsOnlyEE, or Translate8K

I cant stress enough the importance of switching from a sequential files mindset to set-based thinking. After you make the switch, you can spend your time tuning and optimizing your queries instead of maintaining lengthy, poor-performing code. -- Itzik Ben-Gan 2001

Kristen-173977
Kristen-173977
SSCertifiable
SSCertifiable (8K reputation)SSCertifiable (8K reputation)SSCertifiable (8K reputation)SSCertifiable (8K reputation)SSCertifiable (8K reputation)SSCertifiable (8K reputation)SSCertifiable (8K reputation)SSCertifiable (8K reputation)

Group: General Forum Members
Points: 7980 Visits: 662
Very useful function, thank you.

Hopefully not a stupid question?!! but is there is reason why this is a table-valued function rather than scalar?
Alan Burstein
Alan Burstein
SSC Guru
SSC Guru (59K reputation)SSC Guru (59K reputation)SSC Guru (59K reputation)SSC Guru (59K reputation)SSC Guru (59K reputation)SSC Guru (59K reputation)SSC Guru (59K reputation)SSC Guru (59K reputation)

Group: General Forum Members
Points: 59874 Visits: 9221
Thank you for checking it out.

Kristen-173977 (9/16/2015)
Very useful function, thank you.

Hopefully not a stupid question?!! but is there is reason why this is a table-valued function rather than scalar?


This is an excellent question.:-D I asked the same question a few years and the answer made me a much better developer.

The short answer is performance. Inline Table Valued functions (iTVF) generally perform better than scalar user-defined functions. One reason (but certainly not the only reason) is that iTVFs can get a parallel query plan whereas scalar cannot.

PatExclude8K and PatReplace8K are what some people call an inline scalar function. Check out this article: How to Make Scalar UDFs Run Faster it's where I learned the technique I'm talking about.

-- Alan Burstein


Helpful links:

Best practices for getting help on SQLServerCentral -- Jeff Moden
How to Post Performance Problems -- Gail Shaw

Nasty fast set-based string manipulation functions:
For splitting strings try DelimitedSplit8K or DelimitedSplit8K_LEAD (SQL Server 2012+)
To split strings based on patterns try PatternSplitCM
Need to clean or transform a string? try NGrams, PatExclude8K, PatReplace8K, DigitsOnlyEE, or Translate8K

I cant stress enough the importance of switching from a sequential files mindset to set-based thinking. After you make the switch, you can spend your time tuning and optimizing your queries instead of maintaining lengthy, poor-performing code. -- Itzik Ben-Gan 2001

Iwas Bornready
Iwas Bornready
SSC Guru
SSC Guru (74K reputation)SSC Guru (74K reputation)SSC Guru (74K reputation)SSC Guru (74K reputation)SSC Guru (74K reputation)SSC Guru (74K reputation)SSC Guru (74K reputation)SSC Guru (74K reputation)

Group: General Forum Members
Points: 74614 Visits: 886
Thanks for the code.
Go


Permissions

You can't post new topics.
You can't post topic replies.
You can't post new polls.
You can't post replies to polls.
You can't edit your own topics.
You can't delete your own topics.
You can't edit other topics.
You can't delete other topics.
You can't edit your own posts.
You can't edit other posts.
You can't delete your own posts.
You can't delete other posts.
You can't post events.
You can't edit your own events.
You can't edit other events.
You can't delete your own events.
You can't delete other events.
You can't send private messages.
You can't send emails.
You can read topics.
You can't vote in polls.
You can't upload attachments.
You can download attachments.
You can't post HTML code.
You can't edit HTML code.
You can't post IFCode.
You can't post JavaScript.
You can post emoticons.
You can't post or upload images.

Select a forum









































































































































































SQLServerCentral


Search