Skip to main content

Posts

How to create a T-SQL Function to parse a delimited list of numbers and return a table of those numbers

thank you albao This post is related to and a supplement to a previous post  “Pass Delimited List to SQL Server Stored Procedure” Since parsing a delimited string and using the values of a delimited items is a common task in T-SQL, it is a good idea to create a T-SQL Function that will do the work of parsing the delimited string and then return the values in a Table. Once the Function is created, you can call the Function from a Stored Procedure, Query, or whatever else can call a Function. For our example, imagine you have a Table of Users. Where the table consists of the Columns: FirstName, LastName, EmailAddress, and ReceiveNewsletter. Our imaginary application has a feature that will send out monthly newsletters to users that would like to receive the monthly newsletters. To keep track of whether or not a user would like to receive the newsletter, we have a column in the Users table that accepts a bit value (True/False). Now imagine the scenario where you want to cre...