I have data stored the following way in [Table]:
WEEK | Number | Restrict
2018-1 | 1 | 101;102;103
2018-2 | 2 | 101;102;104;105
...
I would like to be able to select the results of [Number] and [Restrict] for a selected week, and then split the [Restrict] into individual results in a temp table.
Based on what I've found so far, I can use the following to split the [Restrict] column into individual rows, based on this article: Break down a delimited string into a temporary table
USE [database];
DECLARE @Week nvarchar(50);
DECLARE @Restrict VARCHAR(MAX);
SET @Week = '2018-1';
SET @Restrict = (SELECT [Restrict] FROM [dbo].[Table] WHERE [Week] = @Week);
DECLARE @ExclusionData TABLE (
[data] nvarchar(50) NULL
)
INSERT INTO @ExclusionData(data)
SELECT data
FROM dbo.Split(@Restrict, ';') s
SELECT * FROM @ExclusionData
How could I also return the 'Number' column beside each of the 'Restrict' values?