Click here to monitor SSC
SQLServerCentral is supported by Red Gate Software Ltd.
 
Log in  ::  Register  ::  Not logged in
 
 
 
        
Home       Members    Calendar    Who's On


Add to briefcase

Handling Delimited Strings in T-SQL Expand / Collapse
Author
Message
Posted Sunday, September 30, 2007 3:03 AM
Forum Newbie

Forum NewbieForum NewbieForum NewbieForum NewbieForum NewbieForum NewbieForum NewbieForum Newbie

Group: General Forum Members
Last Login: Tuesday, December 9, 2003 12:00 AM
Points: 1, Visits: 1
Comments posted to this topic are about the item Handling Delimited Strings in T-SQL


Harinatha Reddy.G
Smart Software Technologies,
Hyderabad , India.
Post #404637
Posted Friday, February 6, 2009 10:21 AM
SSC-Enthusiastic

SSC-EnthusiasticSSC-EnthusiasticSSC-EnthusiasticSSC-EnthusiasticSSC-EnthusiasticSSC-EnthusiasticSSC-EnthusiasticSSC-Enthusiastic

Group: General Forum Members
Last Login: Tuesday, July 22, 2014 5:24 PM
Points: 154, Visits: 197
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/
Post #651838
Posted Friday, February 6, 2009 10:33 AM


SSCommitted

SSCommittedSSCommittedSSCommittedSSCommittedSSCommittedSSCommittedSSCommittedSSCommitted

Group: General Forum Members
Last Login: Wednesday, February 24, 2010 4:10 AM
Points: 1,553, Visits: 2,232
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


Posting Best Practices
Numbers / Tally Tables

SQL-4-Life
Post #651841
« Prev Topic | Next Topic »

Add to briefcase

Permissions Expand / Collapse