« Dynamic PIVOT | Main | Renaming SQL Server »

FN_Split() Table Valued Function

Fn_Split()

The link above is to a file with a table-valued function called fn_split(). This function allows you to pass a string of values to an IN clause of a SQL query. It breaks them down into a set of rows in a virtual table. Then you use a subquery in the IN clause. 

This function is very useful when passing multi-valued parameters in a SQL Server Reporting Services report into a stored procedure.  The parameter is defined in the stored procedure as a large varchar string (max 8000 character).  In the stored procedure you would reference the function in the WHERE clause where you  want to use the multiple parameter values. 

Example:

SELECT *
FROM table
WHERE column IN (SELECT [value] FROM dbo.fn_split(@parameter, ','))

Posted on Friday, December 8, 2006 at 03:45PM by Registered CommenterJeff Jones in , , | CommentsPost a Comment

PrintView Printer Friendly Version

EmailEmail Article to Friend

Reader Comments

There are no comments for this journal entry. To create a new comment, use the form below.
Editor Permission Required
You must have editing permission for this entry in order to post comments.