|
|
|
SSC-Enthusiastic
      
Group: General Forum Members
Last Login: Wednesday, February 01, 2012 6:49 AM
Points: 178,
Visits: 463
|
|
|
|
|
|
SSC-Enthusiastic
      
Group: General Forum Members
Last Login: Today @ 2:30 AM
Points: 140,
Visits: 491
|
|
|
|
|
|
SSC-Dedicated
           
Group: General Forum Members
Last Login: Today @ 7:18 AM
Points: 33,112,
Visits: 27,038
|
|
|
|
|
|
SSC-Dedicated
           
Group: General Forum Members
Last Login: Today @ 7:18 AM
Points: 33,112,
Visits: 27,038
|
|
Eralper (7/10/2009) Actually, I made a simple test to see that the xml function is quicker.
Actually, let's see THAT test. I already posted mine.
--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."
For better, quicker answers on T-SQL questions, click on the following... http://www.sqlservercentral.com/articles/Best+Practices/61537/
For better answers on performance questions, click on the following... http://www.sqlservercentral.com/articles/SQLServerCentral/66909/
|
|
|
|
|
Grasshopper
      
Group: General Forum Members
Last Login: Thursday, February 28, 2013 5:42 AM
Points: 10,
Visits: 40
|
|
Hi all, sorry for the late reply...
I agreed with performance issue of SQL function incase of too large string needs to be split.
hence, i have slightly modified the SQL function which makes better performance.
Please try the below code...
CREATE function Split_fn ( @split_string varchar(8000), @deli_char varchar(3) ) returns @list table ( SeqNo int, SplitString varchar(8000) Primary Key (SeqNo) ) as begin
declare @from_loc int declare @to_loc int
if charindex(@deli_char,@split_string,0) <= 0 begin insert into @list(seqno, SplitString) values (1, @split_string) return end
if charindex(@deli_char,@split_string,0) > 0 begin select @from_loc = 0 select @to_loc = charindex(@deli_char,@split_string,0) end if charindex(@deli_char,@split_string,0) <= 0 begin select @to_loc = null end
while @to_loc is not null begin
if substring(@split_string,@from_loc, @to_loc - @from_loc) <> '' begin insert into @list(seqno, SplitString) select isnull(max(seqno),0) + 1, substring(@split_string,@from_loc, @to_loc - @from_loc) from @list end select @from_loc = charindex(@deli_char,@split_string,@from_loc+len(@deli_char)) + len(@deli_char) select @to_loc = charindex(@deli_char,@split_string,@from_loc)
if @to_loc = 0 begin if substring(@split_string,@from_loc, (len(@split_string) - @from_loc) + len(@deli_char)) <> '' begin insert into @list(seqno, SplitString) select isnull(max(seqno),0) + 1, substring(@split_string,@from_loc, (len(@split_string) - @from_loc) + len(@deli_char)) from @list end select @to_loc = null end end return end
With regards, Rafidheen.M
|
|
|
|
|
Grasshopper
      
Group: General Forum Members
Last Login: Thursday, February 28, 2013 5:42 AM
Points: 10,
Visits: 40
|
|
| I have defined @split_string, SplitString (column) as varchar(8000). For 2005 or later users it can be varchar(max) (for too large string process)which will not affect the performance..
|
|
|
|
|
SSC-Dedicated
           
Group: General Forum Members
Last Login: Today @ 7:18 AM
Points: 33,112,
Visits: 27,038
|
|
|
|
|
|
Grasshopper
      
Group: General Forum Members
Last Login: Tuesday, September 04, 2012 2:14 AM
Points: 14,
Visits: 93
|
|
Jeff,
I maintain the fastest way of splitting a string is a combined process.
1. Pass the string, delim, to clr function 2. The clr function converts each item in to a fixed char width item, eg 20 chars per item. 3. The returned string is split by an inline function querying a tally table using substring.
I've tried all other methods and they are much slower.
Pure clr is slow because it is slow to pass back so many records.
Pure SQL is slow because it is slow at lookup and constructor functions.
Jeff, if you want the exact code, happy to send it through.
|
|
|
|
|
SSC-Dedicated
           
Group: General Forum Members
Last Login: Today @ 7:18 AM
Points: 33,112,
Visits: 27,038
|
|
sam.walker (5/9/2011) Jeff,
I maintain the fastest way of splitting a string is a combined process.
1. Pass the string, delim, to clr function 2. The clr function converts each item in to a fixed char width item, eg 20 chars per item. 3. The returned string is split by an inline function querying a tally table using substring.
I've tried all other methods and they are much slower.
Pure clr is slow because it is slow to pass back so many records.
Pure SQL is slow because it is slow at lookup and constructor functions.
Jeff, if you want the exact code, happy to send it through.
I've not found CLR code to be slow for splitters when they're done properly. Please see the code at the article I posted and test yours against the code that's in there and then post your results here. There's also a standard test data setup for your tests. A simple modification of the code to include your method will allow the automatic running and reporting of your code and the other CLR for 1-10, 10-20, 20-30, 30-40, and 40-50 random length elements across an even wider range of number of elements. Why do I want you to do it? After that article, I'm a bit burned out on testing everyone else's code. 
Also, what do you do when you have items that are 21 characters in length?
--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."
For better, quicker answers on T-SQL questions, click on the following... http://www.sqlservercentral.com/articles/Best+Practices/61537/
For better answers on performance questions, click on the following... http://www.sqlservercentral.com/articles/SQLServerCentral/66909/
|
|
|
|