Click here to monitor SSC
SQLServerCentral is supported by Redgate
Log in  ::  Register  ::  Not logged in

Get your favorite SSC scripts directly in SSMS with the free SQL Scripts addin. Search for scripts directly from SSMS, and instantly access any saved scripts in your SSC briefcase from the favorites tab.
Download now (direct download link)

Function to Split a Delimited String into a Table

By Andy B.,

This function splits a delimited string (up to 4000 characters long) into a single column table. The delimiter can be specified at the time of execution. If not specified, the delimiter defaults to a comma. The default length of each value is 100, but that can easily be changed.
An example for usage:
DECLARE @string NVARCHAR(4000)
DECLARE @instruments TABLE (instrument NVARCHAR(100))
SET @string = 'guitar, flute, snare drum, bass drum, trumpet'
INSERT INTO @instruments (instrument)
SELECT value FROM dbo.fnDStringToTable(@string, ',')
SELECT instrument FROM @instruments

Total article views: 5268 | Views in the last 30 days: 17
Related Articles

Get String between two delimiters

Get string between two delimiters


Delimited String Parser

Parses delimited string into a table of up to 9 varchar fields.


Extracting Rows from Delimited Strings

Extracting Rows from Delimited Strings


Split string using multiple delimiters

This script is used to split the string using multiple delimiters



This Friday Steve Jones is looking for the instrumentation or monitoring that you build into your ap...