SQLServerCentral is supported by Red Gate Software Ltd.
 
Log in  ::  Register  ::  Not logged in
 
 
 

Function to Split a Delimited String into a Table

By Andy Brown, 0001/01/01

Total article views: 3676 | Views in the last 30 days: 97

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

By Andy Brown, 0001/01/01

Total article views: 3676 | Views in the last 30 days: 97
Your response
 
 
Related Articles
SCRIPT

Delimited String Parser

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

FORUM

Extracting Rows from Delimited Strings

Extracting Rows from Delimited Strings

SCRIPT

Delimited String Parsing Functions - Big Set

Feed it large strings of delimited horizontal data and it returns it back as a vertical table.

SCRIPT

Delimited String Parsing Functions - Big2D set

Feed it large strings of double-delimited horizontal data and it returns it back as a non-pivoted ve...

SCRIPT

Delimited String Parsing Functions - TwoCol set

Feed it two delimited strings of horizontal data and it returns it back as a vertical table with the...

 
Contribute

Free registration required...

To read the rest of this article, and access thousands of other articles, we ask you to register on the site and subscribe to our newsletters.

Login (existing users)

Login

Email:   Password:   Remember me: Forgotten your password?

Register (new users)

Register

Email:   Password:
Confirm:

Subscribing to our newsletters gets you:

  • ALL of our content (thousands of articles, scripts, and forum postings)
  • A daily newsletter (example)
  • A weekly news round up (example)
  • The opportunity to ask and answer questions in our forums
  • A daily Question of the Day to test and help you increase your knowledge of SQL Server.

Steve Jones
Editor, SQLServerCentral.com