views:

22

answers:

1
ItemCode    AttributeCode        AttributeValue
----------- -------------------- ----------------
ITEM-000001 BUTTONS              2B
ITEM-000001 COLOR                NAVY
ITEM-000001 FABRIC               A-W
ITEM-000001 LAPEL                NOTCH
ITEM-000001 PATTERN              STRIPE
ITEM-000001 SEASON               A6
ITEM-000001 SUITSTYLE            SB
ITEM-000001 VENT                 NONE

How i can show above data in single row as those are having same ItemCode?

Kind regards, Om

+1  A: 

Try this:

SELECT ItemCode, 
   (SELECT AttributeValue FROM Table x WHERE x.ItemCode = t.ItemCode AND x.AttributeCode = 'BUTTONS') as [Buttons],
   (SELECT AttributeValue FROM Table x WHERE x.ItemCode = t.ItemCode AND x.AttributeCode = 'COLOR') as [Color],
   ..... repeat for all .....
FROM Table t
GROUP BY ItemCode
ck
Thank you.Is there is other way to manage those dynamically, if in future the columns data 'AttributeCode' will having more data?
Om
Only by generating your code dynamically. You can also look into `PIVOT`, however that has to have all of the items hard coded as well.
ck
I think that we can create dynamic select query by using column data through Cursor or there is any other way we can create dynamic query?
Om
It could be done completely in SQL using a cursor, however I would try and build the SQL in an external language if possible.
ck