I need to sort based on the values sent from the input xml column resultdata
this is an value which i have in my database, sent from front end.
currently the dispaly is based on database storage level of master data. i will not be able to change the master data ordering. based on selection, i have to sort since i have an logic which stored the data into resultdata column
CREATE TABLE [dbo].[Table_temp]( [ProdCode] [nchar](5) NULL, [ProductName] [nchar](50) NULL ) ON [PRIMARY] GO INSERT [dbo].[Table_temp] ([ProdCode], [ProductName]) VALUES (N'RD ', N'Bus ') INSERT [dbo].[Table_temp] ([ProdCode], [ProductName]) VALUES (N'SA ', N'Ship ') INSERT [dbo].[Table_temp] ([ProdCode], [ProductName]) VALUES (N'TR ', N'Train ') INSERT [dbo].[Table_temp] ([ProdCode], [ProductName]) VALUES (N'AI ', N'Plane ') CREATE TABLE [dbo].[Table_result]( [resultdata] [nvarchar](max) NULL ) ON [PRIMARY] TEXTIMAGE_ON [PRIMARY] GO INSERT [dbo].[Table_result] ([resultdata]) VALUES (N'AI,RD,TR,SA') INSERT [dbo].[Table_result] ([resultdata]) VALUES (N'SA,TR,RD') Select RTRIM(LTRIM(STUFF((SELECT ',' + RTRIM(LTRIM(ProductName)) FROM Table_temp WHERE ',' + t.resultdata + ',' LIKE '%,' + RTRIM(LTRIM(ProdCode)) + ',%' FOR XML PATH('')),1,1,''))) AS ProductInfo ,t.resultdata FROM ( SELECT resultdata FROM Table_result ) t /* -- Displaying result ProductInfo resultdata Bus,Ship,Train,Plane AI,RD,TR,SA Bus,Ship,Train SA,TR,RD --- Expected result based on the infomation from inserted resultdata sorting order. ProductInfo resultdata Plane,Bus,Train,Ship AI,RD,TR,SA Ship,Train,Bus SA,TR,RD */
Kindly suggset