Click here to monitor SSC
SQLServerCentral is supported by Red Gate Software Ltd.
 
Log in  ::  Register  ::  Not logged in
 
 
 
        
Home       Members    Calendar    Who's On


Add to briefcase ««1234»»»

Remove non printable characters Expand / Collapse
Author
Message
Posted Friday, February 26, 2010 9:48 PM


SSCrazy Eights

SSCrazy EightsSSCrazy EightsSSCrazy EightsSSCrazy EightsSSCrazy EightsSSCrazy EightsSSCrazy EightsSSCrazy EightsSSCrazy EightsSSCrazy Eights

Group: General Forum Members
Last Login: Today @ 6:55 AM
Points: 9,928, Visits: 11,203
--- Duff code removed ---



Paul White
SQL Server MVP
SQLblog.com
@SQL_Kiwi
Post #873849
Posted Friday, February 26, 2010 10:46 PM


SSC-Dedicated

SSC-DedicatedSSC-DedicatedSSC-DedicatedSSC-DedicatedSSC-DedicatedSSC-DedicatedSSC-DedicatedSSC-DedicatedSSC-DedicatedSSC-DedicatedSSC-DedicatedSSC-DedicatedSSC-Dedicated

Group: General Forum Members
Last Login: Today @ 2:42 PM
Points: 35,768, Visits: 32,431
Paul White (2/26/2010)
Hey Jeff,

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


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."

(play on words) "Just because you CAN do something in T-SQL, doesn't mean you SHOULDN'T." --22 Aug 2013

Helpful Links:
How to post code problems
How to post performance problems
Post #873873
Posted Friday, February 26, 2010 10:50 PM


SSC-Dedicated

SSC-DedicatedSSC-DedicatedSSC-DedicatedSSC-DedicatedSSC-DedicatedSSC-DedicatedSSC-DedicatedSSC-DedicatedSSC-DedicatedSSC-DedicatedSSC-DedicatedSSC-DedicatedSSC-Dedicated

Group: General Forum Members
Last Login: Today @ 2:42 PM
Points: 35,768, Visits: 32,431
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."

(play on words) "Just because you CAN do something in T-SQL, doesn't mean you SHOULDN'T." --22 Aug 2013

Helpful Links:
How to post code problems
How to post performance problems
Post #873877
Posted Friday, February 26, 2010 10:55 PM


SSCrazy Eights

SSCrazy EightsSSCrazy EightsSSCrazy EightsSSCrazy EightsSSCrazy EightsSSCrazy EightsSSCrazy EightsSSCrazy EightsSSCrazy EightsSSCrazy Eights

Group: General Forum Members
Last Login: Today @ 6:55 AM
Points: 9,928, Visits: 11,203
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
SQL Server MVP
SQLblog.com
@SQL_Kiwi
Post #873880
Posted Monday, March 15, 2010 7:03 AM
SSC-Enthusiastic

SSC-EnthusiasticSSC-EnthusiasticSSC-EnthusiasticSSC-EnthusiasticSSC-EnthusiasticSSC-EnthusiasticSSC-EnthusiasticSSC-Enthusiastic

Group: General Forum Members
Last Login: Monday, May 5, 2014 8:24 AM
Points: 133, Visits: 617
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
Post #882895
Posted Monday, March 15, 2010 7:23 AM


SSCrazy Eights

SSCrazy EightsSSCrazy EightsSSCrazy EightsSSCrazy EightsSSCrazy EightsSSCrazy EightsSSCrazy EightsSSCrazy EightsSSCrazy EightsSSCrazy Eights

Group: General Forum Members
Last Login: Today @ 6:55 AM
Points: 9,928, Visits: 11,203
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

Thank you for the interesting question.




Paul White
SQL Server MVP
SQLblog.com
@SQL_Kiwi
Post #882912
Posted Thursday, April 1, 2010 11:53 AM
Grasshopper

GrasshopperGrasshopperGrasshopperGrasshopperGrasshopperGrasshopperGrasshopperGrasshopper

Group: General Forum Members
Last Login: Thursday, November 20, 2014 4:06 PM
Points: 10, Visits: 114
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
Post #895159
Posted Friday, April 2, 2010 12:53 AM


SSCrazy Eights

SSCrazy EightsSSCrazy EightsSSCrazy EightsSSCrazy EightsSSCrazy EightsSSCrazy EightsSSCrazy EightsSSCrazy EightsSSCrazy EightsSSCrazy Eights

Group: General Forum Members
Last Login: Today @ 6:55 AM
Points: 9,928, Visits: 11,203
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
SQL Server MVP
SQLblog.com
@SQL_Kiwi
Post #895473
Posted Friday, April 2, 2010 4:34 AM


SSCrazy Eights

SSCrazy EightsSSCrazy EightsSSCrazy EightsSSCrazy EightsSSCrazy EightsSSCrazy EightsSSCrazy EightsSSCrazy EightsSSCrazy EightsSSCrazy Eights

Group: General Forum Members
Last Login: Today @ 6:55 AM
Points: 9,928, Visits: 11,203
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
SQL Server MVP
SQLblog.com
@SQL_Kiwi
Post #895509
Posted Friday, April 2, 2010 8:32 AM
Grasshopper

GrasshopperGrasshopperGrasshopperGrasshopperGrasshopperGrasshopperGrasshopperGrasshopper

Group: General Forum Members
Last Login: Thursday, November 20, 2014 4:06 PM
Points: 10, Visits: 114
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?
Post #895668
« Prev Topic | Next Topic »

Add to briefcase ««1234»»»

Permissions Expand / Collapse