Development resources, articles, tutorials, code samples, tools and downloads for ASP.Net, SQL Server, Reporting Services, T-SQL, Windows, AWS, SAP HANA and ABAP
Recursive Function Sample - SQL Server Recursive T-SQL Split Function
Here in this tutorial database developers can find a recursive function sample T-SQL split function which uses recursive CTE (common table expressions) structure in its source code.
If you are working as a SQL Developer or working as an database administrator (DBA), you might probably require a handy t-sql user-defined function, stored procedure or statement that will split an input string (nvarchar data) into pieces according to a given seperator character.
I'm working on my company as a developer and frequently I had to develop t-sql code blocks that will solve problems on SQL Server. T-SQL Recursive Split User-Defined function is one that I programmed for splitting text.
This sample T-SQL recursive split function will work successfully on Microsoft SQL Server 2005 and later versions up to most recent SQL Server 2019.
In addition to given split string SQL functions in this database development tutorial, with SQL Server 2016 SQL developers can use built-in STRING_SPLIT SQL Split String Function
MSSQL Split Function Example
Here is an example usage of the T-SQL SPLIT function in action
And you can find the t-sql source code or the sql definition of the T-SQL Recursive Split Function.
I hope this MSSQL split recursive function for splitting strings in sql will be useful for you.
Here is an other version of the above T-SQL split string function which returns a number showing the order of the splitted string.
SQL String Split Function with Additional Parameters
By adding additional parameters we can empower the SQL string split function to use it in more complex scenarios.
Following user defined function SQLSplitString accepts four parameters:
@string for input concatenated string expression
@seperator for one character seperator to split input string according to
@trim if space characters are not allowed at the beginning and at the end of the splitted pieces
@returnEmptyStrings if the developer wants to eliminate the null or empty string pieces from the returned result set
Here is the source codes of this split string function in SQL