Pulivarthi Sasidhar (10/22/2013)
Hi,Use the following Function....
CREATE FUNCTION fn_getrowsfrmCSVstring(@str varchar(max))
returns @rtn table (id int identity(1,1),value varchar(2000))
As
Begin
Declare
@mstr varchar(max),@i INT,@len INT
SELECT @mstr=@str,@len=LEN(@str),@i=1
WHILE @i<@len
BEGIN
IF CHARINDEX(',',@str)>0
SELECT @STR=SUBSTRING(@str,1,CHARINDEX(',',@str)-1)
ELSE
Select @STR=SUBSTRING(@str,1,LEN(@str))
INSERT INTO @rtn SELECT @STR
SET @i=@i+LEN(@str)+1
SET @STR=SUBSTRING(@mstr,@i,@len)
END
Return
END
Just guessing mind you but I believe the DelimitedSplit8K FUNCTION will be a tad faster than this approach. Suggest you read the linked article as well.
My thought question: Have you ever been told that your query runs too fast?
My advice:
INDEXing a poor-performing query is like putting sugar on cat food. Yeah, it probably tastes better but are you sure you want to eat it?
The path of least resistance can be a slippery slope. Take care that fixing your fixes of fixes doesn't snowball and end up costing you more than fixing the root cause would have in the first place.
Need to UNPIVOT? Why not CROSS APPLY VALUES instead?[/url]
Since random numbers are too important to be left to chance, let's generate some![/url]
Learn to understand recursive CTEs by example.[/url]
[url url=http://www.sqlservercentral.com/articles/St