I work on sql server 2012 i need to get featurekey and feature value separated $
Based on partid but i don't know how o do that by select sql query ?
expected result as below
| PartId | Featurekey | FeatureValue |
| 1550 | Botato$Mango$dates | Yellow$Red$Black |
| 1600 | Rice$macrona$chicken | white$Red$Yellow |
| 1700 | Guava$grapes$FIG | Yellow$Green$Red |
SQL
create table #PartsFeature
(
PartId int,
Featurekey nvarchar(200),
FeatureValue nvarchar(200),
)
insert into #PartsFeature(PartId,Featurekey,FeatureValue)
values
(1550,'Botato','Yellow'),
(1550,'Mango','Red'),
(1550,'dates','Black'),
(1600,'Rice','white'),
(1600,'macrona','Red'),
(1600,'chicken','Yellow'),
(1700,'Guava','Yellow'),
(1700,'grapes','Green'),
(1700,'FIG','Red')
Sachin SinghRank #66 · 26.2K reputationPosted Oct 28, 2021, 12:32 AM EDT
Sachin SinghRank #66 · 26.2K reputationPosted Oct 28, 2021, 12:41 AM EDT
Srinivasan RamamoorthiRank #877 · 2.5K reputationPosted Oct 27, 2021, 11:09 PM EDT
One option that comes to my mind immediately is to create a stored procedure, have a cursor and fetch these columns. Then Iterate the cursor and split feature key and value using substring and store the values in a temp table. Once you have inserted records in temp table, insert it to parts feature table.
Srinivasan RamamoorthiRank #877 · 2.5K reputationPosted Oct 27, 2021, 11:13 PM EDT
Sachin SinghRank #66 · 26.2K reputationPosted Oct 28, 2021, 12:35 AM EDT
Kirtesh ShahRank #250 · 10K reputationPosted Oct 28, 2021, 1:44 AM EDT