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


Remove non printable characters


Remove non printable characters

Author
Message
Paul White
Paul White
SSCoach
SSCoach (15K reputation)SSCoach (15K reputation)SSCoach (15K reputation)SSCoach (15K reputation)SSCoach (15K reputation)SSCoach (15K reputation)SSCoach (15K reputation)SSCoach (15K reputation)

Group: General Forum Members
Points: 15912 Visits: 11355
--- Duff code removed ---



Paul White
SQLPerformance.com
SQLblog.com
@SQL_Kiwi
Jeff Moden
Jeff Moden
SSC Guru
SSC Guru (87K reputation)SSC Guru (87K reputation)SSC Guru (87K reputation)SSC Guru (87K reputation)SSC Guru (87K reputation)SSC Guru (87K reputation)SSC Guru (87K reputation)SSC Guru (87K reputation)

Group: General Forum Members
Points: 87148 Visits: 41113
Paul White (2/26/2010)
Hey Jeff,

Scalar T-SQL functions?! WHILE loops? I am genuinely shocked! w00t


Me too! I guess I've cut way too far back on the coffee and pork chops.

Cool code, Paul. Thanks.

--Jeff Moden

RBAR is pronounced ree-bar and is a Modenism for Row-By-Agonizing-Row.
First step towards the paradigm shift of writing Set Based code:
Stop thinking about what you want to do to a row... think, instead, of what you want to do to a column.
If you think its expensive to hire a professional to do the job, wait until you hire an amateur. -- Red Adair

Helpful Links:
How to post code problems
How to post performance problems
Forum FAQs
Jeff Moden
Jeff Moden
SSC Guru
SSC Guru (87K reputation)SSC Guru (87K reputation)SSC Guru (87K reputation)SSC Guru (87K reputation)SSC Guru (87K reputation)SSC Guru (87K reputation)SSC Guru (87K reputation)SSC Guru (87K reputation)

Group: General Forum Members
Points: 87148 Visits: 41113
Ramesh Saive (2/8/2010)
Jeff Moden (2/6/2010)
...... I should have qualified my statement. Instead of saying...

"I believe you'll find it's a wee bit more difficult to do than just using REPLACE."

... I should have said...

"I believe you'll find it's a wee bit more difficult to do it in a high performance manner using just REPLACE.".......


I knew it was coming, Jeff.:-) I know you would always come up with more optimized solution than this.

And I agree with you on the reusable optimized code; there is really no harm in using optimized code though it is for a one time or one row execution.

Thank you Jeff, for taking time and letting me know few of the cases where a while loop beats a tally table.

I wonder how many more cases I would see where a while loop beats a tally table.:-)


Heh... guess I'm shootin' blanks, lately. Paul White's code above is much faster. Like he said, "an order of magnitude faster". Thanks for the compliment anyway, Ramesh.

--Jeff Moden

RBAR is pronounced ree-bar and is a Modenism for Row-By-Agonizing-Row.
First step towards the paradigm shift of writing Set Based code:
Stop thinking about what you want to do to a row... think, instead, of what you want to do to a column.
If you think its expensive to hire a professional to do the job, wait until you hire an amateur. -- Red Adair

Helpful Links:
How to post code problems
How to post performance problems
Forum FAQs
Paul White
Paul White
SSCoach
SSCoach (15K reputation)SSCoach (15K reputation)SSCoach (15K reputation)SSCoach (15K reputation)SSCoach (15K reputation)SSCoach (15K reputation)SSCoach (15K reputation)SSCoach (15K reputation)

Group: General Forum Members
Points: 15912 Visits: 11355
Jeff Moden (2/26/2010)
Me too! I guess I've cut way too far back on the coffee and pork chops.
Cool code, Paul. Thanks.

Not quite so cool - it doesn't work! (Thanks Carl)



Paul White
SQLPerformance.com
SQLblog.com
@SQL_Kiwi
Grinja
Grinja
SSC Veteran
SSC Veteran (257 reputation)SSC Veteran (257 reputation)SSC Veteran (257 reputation)SSC Veteran (257 reputation)SSC Veteran (257 reputation)SSC Veteran (257 reputation)SSC Veteran (257 reputation)SSC Veteran (257 reputation)

Group: General Forum Members
Points: 257 Visits: 618
Hi all,
I've been away on leave and have only recently had time to catch up.
Thanks for all the code samples you were extremely thorough w00t
Paul White
Paul White
SSCoach
SSCoach (15K reputation)SSCoach (15K reputation)SSCoach (15K reputation)SSCoach (15K reputation)SSCoach (15K reputation)SSCoach (15K reputation)SSCoach (15K reputation)SSCoach (15K reputation)

Group: General Forum Members
Points: 15912 Visits: 11355
Grinja (3/15/2010)
Hi all,
I've been away on leave and have only recently had time to catch up.
Thanks for all the code samples you were extremely thorough w00t

Thank you for the interesting question.



Paul White
SQLPerformance.com
SQLblog.com
@SQL_Kiwi
carl.anderson-1037280
carl.anderson-1037280
Valued Member
Valued Member (62 reputation)Valued Member (62 reputation)Valued Member (62 reputation)Valued Member (62 reputation)Valued Member (62 reputation)Valued Member (62 reputation)Valued Member (62 reputation)Valued Member (62 reputation)

Group: General Forum Members
Points: 62 Visits: 127
Paul,

when I run your example code, I get a separate resulting row for every character I'm trying to exclude. I don't see the same behavior in Jeff's code. Are you sure these are equivalent solutions, or am I doing something wrong?

It looks like each individual row returned by your procedure has removed one of the different excluded characters.

Thanks,

Carl
Paul White
Paul White
SSCoach
SSCoach (15K reputation)SSCoach (15K reputation)SSCoach (15K reputation)SSCoach (15K reputation)SSCoach (15K reputation)SSCoach (15K reputation)SSCoach (15K reputation)SSCoach (15K reputation)

Group: General Forum Members
Points: 15912 Visits: 11355
carl.anderson-1037280 (4/1/2010)
when I run your example code, I get a separate resulting row for every character I'm trying to exclude. I don't see the same behavior in Jeff's code. Are you sure these are equivalent solutions, or am I doing something wrong? It looks like each individual row returned by your procedure has removed one of the different excluded characters.

Hey Carl,

Thanks so much for posting here - it sent me an email notification! I have been trying to track this thread down for a few weeks now, since I first realised that the in-line TVF is not equivalent after all - the trick with the multiple-variable assignment is the thing.

I am busy with something else just at the moment, but will correct my posts and submit a revised version in the next few days.

Thanks again!

Paul



Paul White
SQLPerformance.com
SQLblog.com
@SQL_Kiwi
Paul White
Paul White
SSCoach
SSCoach (15K reputation)SSCoach (15K reputation)SSCoach (15K reputation)SSCoach (15K reputation)SSCoach (15K reputation)SSCoach (15K reputation)SSCoach (15K reputation)SSCoach (15K reputation)

Group: General Forum Members
Points: 15912 Visits: 11355
Ok, I have fixed the code in the original post to avoid anyone else using it by mistake.
The new version uses a nested REPLACE:

GO
CREATE FUNCTION dbo.IF_CleanWithReplace
(
@SomeText VARCHAR(100)
)
RETURNS TABLE
WITH SCHEMABINDING
AS RETURN
SELECT cleaned =
REPLACE(
REPLACE(
REPLACE(
@SomeText COLLATE SQL_LATIN1_GENERAL_CP1_CI_AS,
'A', SPACE(0)),
'E', SPACE(0)),
'-', SPACE(0));
GO



Thanks again, Carl.



Paul White
SQLPerformance.com
SQLblog.com
@SQL_Kiwi
carl.anderson-1037280
carl.anderson-1037280
Valued Member
Valued Member (62 reputation)Valued Member (62 reputation)Valued Member (62 reputation)Valued Member (62 reputation)Valued Member (62 reputation)Valued Member (62 reputation)Valued Member (62 reputation)Valued Member (62 reputation)

Group: General Forum Members
Points: 62 Visits: 127
I see. So if you want to remove the full set of 37 unprintable characters, you would have to create 37 levels of nesting with REPLACE. I guess the computer scientist in me is concerned about 37 full string scans per value when Jeff's code only does one. However, Jeff also uses the PATINDEX function and double wildcards, so I guess it says something about the performance of PATINDEX if the nested REPLACE functions are still faster.

Seems like there should be a better way! CLR maybe?

Maybe a better question is, why is a deeply nested REPLACE so much faster than Jeff's solution?
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