November 17, 2009 at 2:26 am
Paul White (11/17/2009)
SDM (11/17/2009)
To the people who can program in a .NET language and recognise when to use it appropriately to complement T-SQL:Fixed that for ya! 😀
SDM (11/17/2009)
The OP stated it had to be SQL 2000.OP? It's an article! And where does it specify 2000? Read it again carefully 😛
Just under the first code segment:
The goal is to convert the sections of multiple spaces of unknown length to a single space each as quickly as possible. There are some additional requirements. You can't make the data any bigger during the process because it might get too big for VARCHAR(8000) (or whatever size the column is) or you can't use VARCHAR(MAX) because you're using SQL Server 2000
If you are going to ask someone to read the article carfully then I suggest doing so yourself 😀
[font="Arial"]_______________________________________________________
Change is inevitable... Except from a vending machine.[/font]
November 17, 2009 at 2:28 am
@brigzy
You really should try your tests with a complete table to be handled instead of single strings. "GO N" is a feature of SSMS which causes "N" separate statements to be send over the network.
Try this:
PRINT CONVERT(VARCHAR(30), GETDATE(), 126);
GO
DECLARE @i INT;
SELECT @i = 1;
GO 10000
PRINT CONVERT(VARCHAR(30), GETDATE(), 126);
GO
I get this result:
2009-11-17T10:22:36.710
Beginning execution loop
Batch execution completed 10000 times.
2009-11-17T10:22:39.150
As you see, I have almost 2,5 seconds for doing nothing 😉
Greets
Flo
November 17, 2009 at 2:49 am
Rob Fisk (11/17/2009)
Just under the first code segment:The goal is to convert the sections of multiple spaces of unknown length to a single space each as quickly as possible. There are some additional requirements. You can't make the data any bigger during the process because it might get too big for VARCHAR(8000) (or whatever size the column is) or you can't use VARCHAR(MAX) because you're using SQL Server 2000
If you are going to ask someone to read the article carfully then I suggest doing so yourself 😀
Easy Rob!!! I did read that bit (it's the only place that matches a search for '2000'. But you tell me how the grammar works there. That's an OR. The way I read it, I'm not using 2000 so it doesn't apply 😛 :w00t: 😛
Paul White
SQLPerformance.com
SQLkiwi blog
@SQL_Kiwi
November 17, 2009 at 3:01 am
My mind converted the OR to an AND since if you could use VARCHAR(MAX) then the first constraint about string length would not apply anyway.
[font="Arial"]_______________________________________________________
Change is inevitable... Except from a vending machine.[/font]
November 17, 2009 at 6:30 am
bornsql (11/16/2009)
Hi how about this code whether this will work fine or notDECLARE @tmpstr2 Varchar(MAX)
SELECT @tmpstr2=replace(OriginalString, char(10) + char(13), '') FROM @demo
SELECT @tmpstr2=replace(@tmpstr2,' ','|')
SELECT @tmpstr2=replace(@tmpstr2,'|','')
SELECT @tmpstr2
In the end this..
The goal is to remove extra spaces.
Always leaving 1 space.
It removes all of the spaces.
It also removes all LF-CR combinationations.
This only works when they are in that order.
Much if not most of the time they would be CR-LF.
Doing them one at a time would work better for generic coding
Looks Like this...
Thegoalistoremoveextraspaces.Alwaysleaving1space.Itremovesallofthespaces.ItalsoremovesallLF-CRcombinationations.Thisonlyworkswhentheyareinthatorder.MuchifnotmostofthetimetheywouldbeCR-LF.Doingthemoneatatimewouldworkbetterforgenericcoding.
November 17, 2009 at 6:55 am
TheSQLGuru (11/16/2009)
GSquared: did you try hard-coded space-strings instead of the pile of replicates? I would HOPE the optimizer would expand those on compile, but if it doesn't that should shave off some CPU ticks....
Yes. It does nothing for the speed, and makes the code a lot harder to read.
- Gus "GSquared", RSVP, OODA, MAP, NMVP, FAQ, SAT, SQL, DNA, RNA, UOI, IOU, AM, PM, AD, BC, BCE, USA, UN, CF, ROFL, LOL, ETC
Property of The Thread
"Nobody knows the age of the human race, but everyone agrees it's old enough to know better." - Anon
November 17, 2009 at 7:27 am
GSquared (11/17/2009)
TheSQLGuru (11/16/2009)
GSquared: did you try hard-coded space-strings instead of the pile of replicates? I would HOPE the optimizer would expand those on compile, but if it doesn't that should shave off some CPU ticks....Yes. It does nothing for the speed, and makes the code a lot harder to read.
Thanks for the followup G2! I had figured the compiler would expand those in the query plan, but dumber things have happened!! 🙂
Best,
Kevin G. Boles
SQL Server Consultant
SQL MVP 2007-2012
TheSQLGuru on googles mail service
November 17, 2009 at 8:41 am
Pretty good trick, but do you really want to subject each row to the triple REPLACE function?
REPLACE is a costly function and will run for a good while when you process millions of rows. I would add something to screen out entries with 2 or more spaces and perform action on those alone.
November 17, 2009 at 8:47 am
Pieter-423357 (11/17/2009)
Pretty good trick, but do you really want to subject each row to the triple REPLACE function?REPLACE is a costly function and will run for a good while when you process millions of rows. I would add something to screen out entries with 2 or more spaces and perform action on those alone.
The code sample in the article has the clause
WHERE CHARINDEX(' ',OriginalString) > 0
[font="Arial"]_______________________________________________________
Change is inevitable... Except from a vending machine.[/font]
November 17, 2009 at 3:32 pm
Florian Reischl (11/17/2009)
@brigzyYou really should try your tests with a complete table to be handled instead of single strings. "GO N" is a feature of SSMS which causes "N" separate statements to be send over the network.
Try this:
PRINT CONVERT(VARCHAR(30), GETDATE(), 126);
GO
DECLARE @i INT;
SELECT @i = 1;
GO 10000
PRINT CONVERT(VARCHAR(30), GETDATE(), 126);
GO
I get this result:
2009-11-17T10:22:36.710
Beginning execution loop
Batch execution completed 10000 times.
2009-11-17T10:22:39.150
As you see, I have almost 2,5 seconds for doing nothing 😉
Greets
Flo
You really should address Thiago who wrote the test data generation SQL. Thiago's script does generate a complete table quite nicely, this we used for testing the techniques. It takes 2 secs to generate the test data table, and not to 'do nothing'.
C# Gnu
____________________________________________________
November 17, 2009 at 3:36 pm
brigzy (11/17/2009)
You really should address Thiago who wrote the test data generation SQL. Thiago's script does generate a complete table quite nicely, this we used for testing the techniques. It takes 2 secs to generate the test data table, and not to 'do nothing'.
True, but to be fair I think Flo was just trying to be helpful - he writes a pretty mean test script 🙂
Paul White
SQLPerformance.com
SQLkiwi blog
@SQL_Kiwi
November 17, 2009 at 3:42 pm
Hi
brigzy (11/17/2009)
You really should address Thiago who wrote the test data generation SQL. Thiago's script does generate a complete table quite nicely, this we used for testing the techniques. It takes 2 secs to generate the test data table, and not to 'do nothing'.
:w00t:
Oups. Apparently I misread his script. Sorry for that.
Just never saw "GO N" to create test data 😉
Greets
Flo
November 17, 2009 at 3:43 pm
Paul White (11/17/2009)
brigzy (11/17/2009)
You really should address Thiago who wrote the test data generation SQL. Thiago's script does generate a complete table quite nicely, this we used for testing the techniques. It takes 2 secs to generate the test data table, and not to 'do nothing'.True, but to be fair I think Flo was just trying to be helpful - he writes a pretty mean test script 🙂
Well
try your tests with a complete table to be handled instead of single strings
and
2,5 seconds for doing nothing
not fair on Theago.
C# Gnu
____________________________________________________
November 17, 2009 at 3:54 pm
brigzy (11/17/2009)
Welltry your tests with a complete table to be handled instead of single strings
Good advice.
brigzy (11/17/2009)
and2,5 seconds for doing nothing
not fair on Theago.
I think you misread the intention - to illustrate the cost of the network round trips. But never mind.
Paul White
SQLPerformance.com
SQLkiwi blog
@SQL_Kiwi
November 17, 2009 at 4:02 pm
Good advice.
? if u check out script ... it does gen table ...
C# Gnu
____________________________________________________
Viewing 15 posts - 76 through 90 (of 425 total)
You must be logged in to reply to this topic. Login to reply