September 30, 2007 at 3:03 am
Comments posted to this topic are about the item Handling Delimited Strings in T-SQL
Harinatha Reddy.G
Smart Software Technologies,
Hyderabad , India.
February 6, 2009 at 10:21 am
I used to write similar code like this for years and then discovered tally tables made it easier and faster IMHO.
Here's an example:
http://www.sqlservercentral.com/scripts/Miscellaneous/31913/
February 6, 2009 at 10:33 am
CREATE FUNCTION dbo.udfStringtoTable
(
@String NVARCHAR(100) ,
@Delimiter CHAR(1)
)
RETURNS @Results TABLE
(String VARCHAR(100))
AS
BEGIN
INSERT INTO @Results
SELECT SUBSTRING(@String+@Delimiter, n,
CHARINDEX(@Delimiter, @String+@Delimiter, n) - n)
FROM tally
WHERE n <= LEN(@String)
AND SUBSTRING(@Delimiter + @String,
n, 1) = @Delimiter
ORDER BY n
RETURN
END
GO
----------------------------------------------
Try to learn something about everything and everything about something. - Thomas Henry Huxley
:w00t:
Posting Best Practices[/url]
Numbers / Tally Tables[/url]
Viewing 3 posts - 1 through 2 (of 2 total)
You must be logged in to reply to this topic. Login to reply