I have a table that has multiple values (and sometimes no values) in the column: ReptDesc. I want to extract those values in the following way: If a value is followed by a colon : that is to be considered a "column" and the values following the colon, and separated by a semicolon are to be considered rows for that column. Sometimes there will be data and sometimes there will not be in the field "ReptDesc"
Here is the sample data:
Declare @rept table(Id int Identity(1,1), ReptDesc varchar(max))Insert into @rept (ReptDesc)
Values(
'Category: Projects; Accounting and Operations; Sales
Description: this is a transaction report'),
('Category: Technical, Accounting
Description:'),
('Category: Accounting'),
('Category: Accounting, Sales'),
(Null),
(Null)
Select * from @rept
The output I am looking to retrieve from the above is:
Thank you
Image may be NSFW.
Clik here to view.
John