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)

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: 356 | Views in the last 30 days: 1
 
Related Articles
FORUM

Update Script to select

Update Script to select

FORUM

Extracting Rows from Delimited Strings

Extracting Rows from Delimited Strings

BLOG

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...

FORUM

comma delimited name column

comma delimited name column

SCRIPT

Get Item from Delimited List at Position

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

 
Contribute