I have a tables like the following
CREATE TABLE Company
(
Id INT
)
CREATE TABLE CompanyNumbers
(
CompanyId INT,
NumberText VARCHAR (255)
)
What I want as an output is this in pseudo code
Give me all the numbers for company A as a single comma separated string, if the string contains more than 150 numbers output another row with next 150 until complete.
What is the best way to achieve this? basically output batches of 150 numbers like this:
CompanyId | Batch
1 | 3344,444,5555,6444, 444, 44, 44555, 5555... > 150 of them
2 | 33343,33, 2233,3 (second row if more than 150)
I want this to be done within a stored procedure.