Quantcast
Viewing latest article 5
Browse Latest Browse All 5

Parse data from a table row and output the values formatted

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


Viewing latest article 5
Browse Latest Browse All 5

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>