Click here to Skip to main content
15,067,335 members
Please Sign up or sign in to vote.
1.00/5 (2 votes)
See more: , +
hi ,
I have Table Servive,i just Wanto retreve Column headings As Description and Values As Next Column

[IncomeHeadID][InventoryControlHeadID],[CostOfGoodLabHeadID] ,[CostOfGoodHeadID] [CashHeadID]
    12             11                        22                       44            44


i want like this
Description                Value
[IncomeHeadID]              12
[InventoryControlHeadID]     11
[CostOfGoodLabHeadID]        22
[CostOfGoodHeadID]           44
[CashHeadID]                 44


thanks In advance...
Posted
Updated 17-Sep-13 2:05am
v2
Comments
abbaspirmoradi 17-Sep-13 8:07am
   
Maciej Los 17-Sep-13 8:09am
   
Based on what codition?

If you know the heading names or want to change them just do this:

Select "income head Id" as incomeHeadIdDescripton, IncomeHeadId,
"Inventory control head Id" as IncomeControlHeadIdDescription, IncomeControlHeadId
From table 1;

Not sure if you can load column names dynamically from a query, but could if you used a database component...
   
   
v2
I am not pretty sure that this link would give you the exact solution, but this would help you to solve the requirement.

Here is the link,
http://msdn.microsoft.com/en-us/library/ms177410(v=sql.105).aspx[^]
   
Try below script. This requires that you know column names in advance, and I think that is the case here


SQL
DECLARE @Table TABLE ([IncomeHeadID] INT, [InventoryControlHeadID] INT,[CostOfGoodLabHeadID] INT ,[CostOfGoodHeadID] INT, [CashHeadID] INT)
INSERT @Table VALUES (12,11,22,44,44)

SELECT Description, Value
FROM
(SELECT *
FROM @Table) pvt
UNPIVOT ( Description FOR Value IN (
[IncomeHeadID] , [InventoryControlHeadID] ,[CostOfGoodLabHeadID]  ,[CostOfGoodHeadID] , [CashHeadID] ) ) unpvt
   
You can use pivot table for this
   

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)




CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900