By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
458,183 Members | 1,382 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 458,183 IT Pros & Developers. It's quick & easy.

function to extract delimited data

P: n/a
I'd need to have a function that allows me to extract 'fields' from
within the string
I.E. (kinda pseudo code)
declare @foo as varchar(100)
set @foo = "Robert*Camarda*123 Main Street"
select EXTRACT(@foo, '*', 2) ; -- would return 'Camarda'
select EXTRACT(@foo, '*', 3) ;-- returns '123 Main Street'
select EXTRACT(@foo, '*', 0) ;-- would return entire string
select EXTRACT(@foo,'*' , 9) ;-- would return null

Extract( string, text delimiter, occurance)
Anyone have something like this as a user defined function in SQL?
TIA
Rob
Mar 11 '08 #1
Share this Question
Share on Google+
1 Reply


P: n/a
rcamarda (ro**************@gmail.com) writes:
I'd need to have a function that allows me to extract 'fields' from
within the string
I.E. (kinda pseudo code)
declare @foo as varchar(100)
set @foo = "Robert*Camarda*123 Main Street"
select EXTRACT(@foo, '*', 2) ; -- would return 'Camarda'
select EXTRACT(@foo, '*', 3) ;-- returns '123 Main Street'
select EXTRACT(@foo, '*', 0) ;-- would return entire string
select EXTRACT(@foo,'*' , 9) ;-- would return null

Extract( string, text delimiter, occurance)
Anyone have something like this as a user defined function in SQL?
A whole bunch of them here: http://www.sommarskog.se/arrays-in-sql.html.
OK, so none of them returns a specific field from the string,
but several returns a list position to filter on.


--
Erland Sommarskog, SQL Server MVP, es****@sommarskog.se

Books Online for SQL Server 2005 at
http://www.microsoft.com/technet/pro...ads/books.mspx
Books Online for SQL Server 2000 at
http://www.microsoft.com/sql/prodinf...ons/books.mspx
Mar 11 '08 #2

This discussion thread is closed

Replies have been disabled for this discussion.