I am having sql table in that I am having 2 fields as No and declaration
Code Declaration
123 a1-2 nos, a2- 230 nos, a3 - 5nos
I need to display the declaration for that code as:
Code Declaration
123 a1 - 2nos
123 a2 - 230nos
123 a3 - 5nos
I need to split the column data to rows for that code.
For this type of data separation, I would suggest creating a split function:
Then to use this in a query you can use an
outer applyto join to your existing table:Which will produce the result:
See SQL Fiddle with Demo
Or you can implement a CTE version similar to this: