ariel_mlk (9/5/2012)
ALTER FUNCTION [dbo].[SplitString]
(
@String VARCHAR(MAX),
@Delimeter Char(1)
)
RETURNS @RtnValue TABLE
(
Value VARCHAR(100)
)
AS
BEGIN
DECLARE @Cnt INT
SET @Cnt = 1
WHILE (CHARINDEX(@Delimeter, @String) > 0)
BEGIN
INSERT INTO @RtnValue (Value)
SELECT
Data = ltrim(rtrim(Substring(@String,1,Charindex(@Delimeter,@String)-1)))
SET @String = Substring(@String,Charindex(@Delimeter,@String)+1,len(@String))
SET @Cnt = @Cnt + 1
END
INSERT INTO @RtnValue (Value)
SELECT Data = ltrim(rtrim(@String))
RETURN
END
I'm aware this is RBAR and i'm aware of tally techinics but the strings that this functions breaks are usually of something about 200 characters? but mostly it comes as a null, can that make enourmous IO counts?
No offense but if you are aware that this is subpar for performance why not change it out? This process and every other process that uses your splitter will gain an advantage.
_______________________________________________________________
Need help? Help us help you.
Read the article at http://www.sqlservercentral.com/articles/Best+Practices/61537/ for best practices on asking questions.
Need to split a string? Try Jeff Modens splitter http://www.sqlservercentral.com/articles/Tally+Table/72993/.
Cross Tabs and Pivots, Part 1 – Converting Rows to Columns - http://www.sqlservercentral.com/articles/T-SQL/63681/
Cross Tabs and Pivots, Part 2 - Dynamic Cross Tabs - http://www.sqlservercentral.com/articles/Crosstab/65048/
Understanding and Using APPLY (Part 1) - http://www.sqlservercentral.com/articles/APPLY/69953/
Understanding and Using APPLY (Part 2) - http://www.sqlservercentral.com/articles/APPLY/69954/