Hey guys,
Good afternoon!
In this post I will demonstrate a really cool table-valued function that allows you to break a string into a table of substrings using a delimiter in SQL Server. What does this mean? Well, this makes it look like you have a string and the function will transform this string into a table using a separator. In this table, each record will be a part of the string at index i+1 and you can easily work with these substrings.
Interested in learning more about splits?
- Breaking strings into sub-strings using split string
- charindexada: A different function for breaking delimited strings (split)
- Table-valued function to break a string into lines up to N characters long
Examples of using the function

How to implement this in your SQL Server database
This is the coolest part: Get to work!
View source code
Creating the function with the CLR
Another alternative to using this resource is through SQLCLR, a resource that allows you to create .NET code within the database and generally achieves much better performance than Transact-SQL. If you don't know CLR, find out more by accessing the post Introduction to SQL CLR (Common Language Runtime) in SQL Server.
View C# (CLR) function source codeSimple and practical, right?
Hugs!
sql server tsql query table function split explodes text string substring function break word using delimiter delimiter
sql server tsql query table function split explodes text string substring function break word using delimiter delimiter
Comentários (0)
Carregando comentários…