473,434 Members | 1,413 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,434 software developers and data experts.

converting rows to columns

Hi

I have a table which holds the attributes for particular products

prodid prodname feature featurevalue
1 box 1 length 20
1 box 1 width 10
1 box 1 depth 5
1 box 2 length 25
1 box 2 width 20
1 box 2 depth 5


i want to see my results like this so just wondering how do i create the query

prodid prodname length width depth
1 box1 20 10 5
2 box2 25 20 5

i know i can use a case statement

SELECT
prodid,
max(CASE WHEN feature= 'length' THEN featurevalue
END) AS 'length',
max(CASE WHEN feature= 'width' THEN featurevalue
END) AS 'width'
max(CASE WHEN feature= 'depth' THEN featurevalue
END) AS 'depth'
FROM
products
GROUP BY prodid

but my problem is that 1 do not neccessarily know what the features are as these could change between products so i need to make it more dynamic and not hardcode in the feature names..i want it to be able to create columns for all features that might be in my table

any help appreciated
Sep 22 '10 #1
2 839
ck9663
2,878 Expert 2GB
See if this helps.

Good Luck!!!

~~ CK
Sep 22 '10 #2
gpl
152 100+
If you are using MSSQL 2000, then this site has the answer
www.sqlteam.com
Sep 22 '10 #3

Sign in to post your reply or Sign up for a free account.

Similar topics

7
by: Pooj | last post by:
have a urgent requirement. Please somebody help me. I have a table departinfo with following records begin_time end_time Name Pieces 10:00 10:15 PopCorn ...
1
by: dare197 | last post by:
I have a SP that returns the information I want but it returns it in 2 separate queries. Example: Query 1 Name, Number, Class Row 1- Mike Phillips, 154AA, AA and Query 2 Time, Manual
5
by: dnsstaiger | last post by:
I try to accomplish the following: I have two tables which are connected via a third table (N:N relationship): Table 1 "Locations" LocationID (Primary Key) Table 2 "Specialists"...
2
by: J055 | last post by:
Hi I've been looking into different ways of formatting columns/rows in the GridView control. I realize now, I think, that once the datasource is bound to the control the original column type...
0
by: mzladyd | last post by:
This forum has been so helpful to me. Mr Moderator, I know I should at least attempt this myself before asking for help, but I don't know where to begin. My max case 'sql' works fine, but I my 'when'...
1
by: praneethraj | last post by:
i have 2 rows with 3 columns each. ( each rows has a colun called ScoreType which contains different data like Performancelevel,scaledscore Subject Marks ScoreType A ...
2
by: truva | last post by:
Hi, I need a query which would convert Rows into Columns without causing any damages to the original data. I am not supposed to solve this by creating temporary tables and later dropping it. I...
0
by: Orbie | last post by:
Hi Guys, I need some help with pivoting or converting some rows on a Table into columns using SQL Server 2008! I have a Table which contains the same Products in 4 different Stores. I'm only...
6
by: viki1967 | last post by:
Hi all. I need your help. I realize this script and I do not know where to begin: 1) A simple grid rows / columns. 2) The first column contain an input type = "checkbox" 3) When select...
3
by: ronakinuk | last post by:
how can i unhide rows/columns in excel 2007
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
1
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...
0
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The...
0
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.