Never Mind.. I solved it myself. Created a stored procedure to fetch data and stored it in table variable and then used alter column query to add my rows as column of temporary table. After creating the temporary table, I looped through each component and inserted record for each component and sub-component.
Transpose Data coming from SQL Server query into columns
-
29-06-2023 - |
Question
I have following query to get data from multiple tables
SELECT TOP (100) PERCENT
dbo.tblProduct.PK AS PRODUCT_PK, dbo.tblProduct.PRODUCT_NAME,
dbo.tblProductSubComponent.SUB_COMPONENT_PK,
dbo.tblComponent.COMPONENT_NAME, dbo.tblSubComponent.SUB_COMPONENT_NAME
FROM
dbo.tblProductComponent
RIGHT OUTER JOIN
dbo.tblComponent
INNER JOIN
dbo.tblSubComponent
INNER JOIN
dbo.tblComponentSubComponent ON dbo.tblSubComponent.PK = dbo.tblComponentSubComponent.SUB_COMPONENT_PK
ON dbo.tblComponent.PK = dbo.tblComponentSubComponent.COMPONENT_PK
ON dbo.tblProductComponent.COMPONENT_PK = dbo.tblComponent.PK
LEFT OUTER JOIN
dbo.tblProductSubComponent ON dbo.tblSubComponent.PK = dbo.tblProductSubComponent.SUB_COMPONENT_PK
FULL OUTER JOIN
dbo.tblProduct ON dbo.tblProductSubComponent.PRODUCT_PK = dbo.tblProduct.PK AND dbo.tblProductComponent.PRODUCT_PK = dbo.tblProduct.PK
ORDER BY
PRODUCT_PK
The result is
and now I want to show data in gridview like this
Solution
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow