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)

Slice out string from within specified delimiters

By anonuser,

Scalar function 'f_delimited' slices out of a passed-in string, from a specified position inside the string, that segment of it which is delimited on one or both sides by a specified delimiter.

Example:  Print out a segment of a 'syscomments.text' column for a stored procedure 'p_proc', representing a line of code (i.e., the segment of 'syscomments.text' between carriage returns) containing the string '@retc'.

Given:  @line_of_code VARCHAR (200), @pos INT, @delim CHAR (1)

SELECT @delim        = CHAR (13) -- carriage return
     , @pos          = CHARINDEX ('@retc', text)
     , @line_of_code = dbo.f_delimited
                         (@f_string = text
                        , @f_delim  = @delim
                        , @f_pos    = @pos)
FROM syscomments
WHERE id    = OBJECT_ID ('p_proc')
  AND colid = 1



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

Get String between two delimiters

Get string between two delimiters

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

Split string using multiple delimiters

This script is used to split the string using multiple delimiters

SCRIPT

Delimited String Parsing Functions - Big Set

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

Tags
miscellaneous    
 
Contribute

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
Editor, SQLServerCentral.com

Already a member? Jump in:

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