I have a table, Office, with a column that contains lists of ids representing many-to-many relationships:
TABLE Office {
OfficeId int IDENTITY(1,1) NOT NULL,
CubeIds NVARCHAR(MAX) NULL, --values like "8,6,7"; "10,12,14,16"
}
and a destination junction table:
TABLE OfficeToCube {
CubeId INT NOT NULL,
OfficeId INT NOT NULL,
FOREIGN KEY (CubeId) REFERENCES (Cube.CubeId),
FOREIGN KEY (OfficeId) REFERENCES (Office.OfficeId),
}
How can I iterate over both the rows and the comma-separated values in CubeIds, in order to insert them as individual records in OfficeToCube?
CREATE TABLEstatement? anINSERTstatement? something else? – mustaccio Sep 30 '23 at 01:49INSERTstatement to save the results to yourOfficeToCubetable. Granted, if you were on SQL Server 2016 or newer, this would be an easier problem to solve. – J.D. Sep 30 '23 at 03:22