SAMPLE SELECT SQL- USING STRING SPLIT SQL FUNCTION
FUNCTION STRING_SPLIT()
The STRING_SPLIT function applies from the version of SQL Server 2016 and later
A table-valued function that splits a string into rows of substrings, based on a specified separator character.
Return Types:
Returns a single-column table whose rows are the substrings. The name of the column is value. Returns nvarchar if any of the input arguments are either nvarchar or nchar. Otherwise returns varchar. The length of the return type is the same as the length of the string argument.
Remarks
STRING_SPLIT inputs a string that has delimited substrings, and inputs one character to use as the delimiter or separator. STRING_SPLIT outputs a single-column table whose rows contain the substrings. The name of the output column is value.
The output rows might be in any order. The order is not guaranteed to match the order of the substrings in the input string. You can override the final sort order by using an ORDER BY clause on the SELECT statement (ORDER BY value).
Sample 01 - Single Values From Values List Above
1 | Value01 |
2 | Value02 |
3 | Value03 |
4 | Value04 |
5 | Value05 |
6 | Value06 |
Sample 02 - GENERATE TABLE PRODUCT VALUES FROM LIST STRING: (1,Product 01,150.00;2,Produto 02,300.00;3,Produt 03,75.90;4,Product 05,99.90;5,Product 05,450.00)
1 | Product 01 | 150 |
2 | Produto 02 | 300 |
3 | Produt 03 | 75.9 |
4 | Product 05 | 99.9 |
5 | Product 05 | 450 |