SQL Server Central is supported by Red Gate Software Ltd.
 
Log in  ::  Register  ::  Not logged in
Search:  
 
 

UDF: Parse a delimited list of paramters

By Jason, 2006/06/13

Total article views: 69 | Views in the last 30 days: 3

After replying to a post today I thought I'd share this with all.

This is a user defined function that I use to return a table of parameters passed in a parameter string.

Function Usage
Select * From dbo.fnParseParamString ([@ParamString='Delimited String of parmaters'],[@Delimeter='Delimiting Character'])

Lets say you are concatenating a list of form data from a web page where you take the user's First Name, Last Name and email address.

your concatenated string looks like this: John,Doe,jdoe@company.com

Once you've installed the userdefined function you can execute this:

select * from dbo.fnParseParamString('John,Doe,jdoe@company.com',',')

this returns

iRowId vcParameters
----------- --------------------
1 John
2 Doe
3 jdoe@company.com

(3 row(s) affected)

now, since you know Parameter 1 is the first name, and parameter 2 is the last name and parameter 3 is the email address you can do something like this:

select vcParameter from dbo.fnParseParamString('John,Doe,jdoe@company.com',',') where iRowId = 3

which returns the email address portion of the parameter string

vcParameters
--------------------
jdoe@company.com

(1 row(s) affected)

By Jason, 2006/06/13

Total article views: 69 | Views in the last 30 days: 3
Your response
 
 
Related tags

T-SQL Aids    
 
Already registered?  

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.

Register

E-mail address:
Password:
Password (confirm):

  

Subscriptions

We ask you to register on the site and subscribe to our newsletters. 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.

We ask that you give the newsletter a try for a week. Over 200,000 SQL Server Professionals a day find it entertaining and useful. If not, you are welcome to unsubscribe at anytime.

Steve Jones
Editor, SQLServerCentral.com