0

Hi,i have this tblProductAttribute with ProductAttributeID|ProductID|AttributeID|AttributeValue|
1|1|Blue
2|2|medium

(AttributeID 1 = Color,2= size)
i want to get result from select query like this
ProductName|Color|Size
sampleproduct|Blue|Medium

inshort i need to get row data to be the column name
please help me.thanks :-)

3
Contributors
5
Replies
38
Views
3 Years
Discussion Span
Last Post by urtrivedi
0

If you are using MS SQL you can do

SELECT column_name 
  FROM information_schema.columns
 WHERE table_name = 'yourtablename'
 ORDER BY ordinal_position

Edited by Reverend Jim

0
select ProductID , max(case when AttributeID=1 then AttributeValue else null end) Color
, max(case when AttributeID=2 then AttributeValue else null end) Size from tblProductAttribute 
group by ProductID
0

@urtrivedi thanks you very much! i have another question,what if i have unknown number of attributes? In my program,the user can add attributes.

1

You can do this by using php code,
First you have to loop through attribute table and create dynamic query.

Then exucute that query to get the desired result

Votes + Comments
right
This topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.