Click here to monitor SSC
SQLServerCentral is supported by Red Gate Software Ltd.
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)

Revise t-sql function to parse string data

By yzhang1121,

Kmlakov's script, t-sql function to parse string data, posted on 1/19/2005, required the passing in text ends with the delimiter. But it is usually not the case. I rewrote the script (added one IF statement). The new script can treat the text with or without ending delimiter. The third parameter will be the number of delimiters. For example, the following two select statements have the same result:

SELECT * FROM [master].[dbo].[parsestring]('abcd,efg,hij,klm,no,pq,',',',6)

SELECT * FROM [master].[dbo].[parsestring]('abcd,efg,hij,klm,no,pq',',',5)

Total article views: 352 | Views in the last 30 days: 1
Related Articles

Update Script to select

Update Script to select


Extracting Rows from Delimited Strings

Extracting Rows from Delimited Strings


SQL – Split delimited columns using XML Or UDF function

The requirement is to convert the delimited column into rows Input data and required output details...


comma delimited name column

comma delimited name column


Get Item from Delimited List at Position

Returns the item from a delimited list at the specified position. Both position and delimiter are pa...


Join the most active online SQL Server Community

SQL knowledge, delivered daily, free:

Email address:  

You make SSC a better place

As a member of SQLServerCentral, you get free access to loads of fresh content: thousands of articles and SQL scripts, a library of free eBooks, a weekly database news roundup, a great Q & A platform… And it’s our huge, buzzing community of SQL Server Professionals that makes it such a success.

Join us!

Steve Jones

Already a member? Jump in:

Email address:   Password:   Remember me: Forgotten your password?
Steve Jones