I have a query :
create table #mytable (table_id int IDENTITY(1,1), attribute_name varchar(20)) declare @strString varchar(500) set @strString ='Terminal$Attr1,Attr2,Attr3,Attr4,Attr5,Attr6,@Connector$Con1,Con2,Con3,Con4,@Wire$W1,W2,W3,W4,W5,' Set @strString=REPLACE(REPLACE(@strString,'$',','),'@','')--Added ;WITH StrCTE(start, stop) AS ( SELECT 1, CHARINDEX(',' , @strString ) UNION ALL SELECT stop + 1, CHARINDEX(',' ,@strString , stop + 1) FROM StrCTE WHERE stop > 0 ) insert into #mytable SELECT SUBSTRING(@strString , start, CASE WHEN stop > 0 THEN stop-start ELSE 4000 END) AS stringValue FROM StrCTE where SUBSTRING(@strString , start, CASE WHEN stop > 0 THEN stop-start ELSE 4000 END)<>'' --, --case attribute_name --when 'Terminal' then attribute_name like '%Attr%', --when 'Connector' then attribute_name like '%Con%' , --when 'Wire' then attribute_name like '%W%' select * from #mytable the output which I am getting is : enter image description here
I need the output as : enter image description here
I have created family table too.. but unable to write the case and joins to get the result.
The query for family table is :
create table Family (family_id int identity,family_name varchar(300)) insert into Family values ('Terminal') insert into Family values ('Connector') insert into Family values ('Wire') select * from Family