A little normalization is a beautiful thing. Your problem is that your table fails the 1NF test, so you have to use DelimitedSplit8K to break up that delimited string into individual elements. And while I'm at it, DESC is a reserved word in T-SQL. Don't use it as a column name - that's just asking for trouble.
SELECT id
, [desc] AS Descrip
, comm
, cat.Item
FROM UseCase
CROSS APPLY Teest.dbo.DelimitedSplit8K(catgroup,',') cat;
You can find the code for DelimitedSplit8K here.
you can simplify your inserts by doing this:
insert into usecase (id, [desc], comm, catgroup) values(1,'desc 1', 'comment 1', '1')
,(2,'desc 2', 'comment 2', '1,2')
,(3,'desc 3', 'comment 3', '1,2,3')
,(4,'desc 4', 'comment 4', '60,61')
,(5,'desc 5', 'comment 5', '59,60,61')
,(6,'desc 6', 'comment 6', '9,3');
February 24, 2020 at 11:15 pm
Thank you so much for your quick reply. It is working as amazing miracle.
Viewing 2 posts - 1 through 3 (of 3 total)
You must be logged in to reply to this topic. Login to reply