Speak guys !!
I would like to share with you a really cool new feature that I noticed in Azure SQL Database, which was the inclusion of a new parameter in the STRING_SPLIT function and that has been requested since the function was created in SQL Server 2016, which is the inclusion of the number of positions in the return of text breaks.
This function is so new that as of this writing, this new parameter is only available in the English version of the documentation:
For those who don't remember, the use of this function is done like this:
The problem is that the function didn't return the position number, so it was difficult to get the first element or the N element of the return. With that, I myself ended up using other alternatives, as I have already shown in the article How to wrap a string in a substring table using a delimiter in SQL Server and it works on any version of SQL Server.
However, to my surprise, today I found out that Azure SQL Database has already implemented a change to the STRING_SPLIT function and is now allowing you to return the position number:
And now I can choose the elements I want:
If we try to reproduce the same thing in SQL Server 2019, we get this error message:
So I imagine that soon, there should be some update to include this improvement for the On-Premisses versions.
- SQL Server - Charindex: A Different Function to Break Split Strings
- SQL Server - Breaking strings into sub-strings using a separator (Split string)
- SQL Server - Table-valued function to break a string into lines up to N characters long
- How to wrap a string in a substring table using a delimiter in SQL Server
- SQL Server - Using STRING_SPLIT to transform strings from a row into columns
So that's it, guys!
Short, quick and informative post.
A big hug and until next time!