Solved

Group By Question

Posted on 2008-06-09
2
209 Views
Last Modified: 2010-04-21
I have a table that has an id, a type column and a column containing a date.  Each id can have between 1 and 6 rows of data.  I want to group the data in one row so I can display it on a form...i am trying to use the following query but it returns a row for each data type...what do I need to do?

select submittalId,
case DateTypeID when 1 then [Date] End As'QATarget' ,
case DateTypeID when 2 then [Date] End As 'ProductionTarget',
case DateTypeID when 3 then [Date] End As'QASet' ,
case DateTypeID when 4 then [Date] End As 'ProductionSet',
case DateTypeID when 5 then [Date] End As'QAActual' ,
case DateTypeID when 6 then [Date] End As 'ProductionActual'
from dbo.SubmittalDates
0
Comment
Question by:PsychoDazey
2 Comments
 
LVL 39

Accepted Solution

by:
appari earned 500 total points
ID: 21747919
try

select submittalId,
max(case DateTypeID when 1 then [Date] End) As'QATarget' ,
max(case DateTypeID when 2 then [Date] End) As 'ProductionTarget',
max(case DateTypeID when 3 then [Date] End) As 'QASet' ,
max(case DateTypeID when 4 then [Date] End) As 'ProductionSet',
max(case DateTypeID when 5 then [Date] End) As 'QAActual' ,
max(case DateTypeID when 6 then [Date] End) As 'ProductionActual'
from dbo.SubmittalDates
group by submittalId
0
 
LVL 6

Author Closing Comment

by:PsychoDazey
ID: 31465607
perfect, thanks!
0

Featured Post

Enterprise Mobility and BYOD For Dummies

Like “For Dummies” books, you can read this in whatever order you choose and learn about mobility and BYOD; and how to put a competitive mobile infrastructure in place. Developed for SMBs and large enterprises alike, you will find helpful use cases, planning, and implementation.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Ever wondered why sometimes your SQL Server is slow or unresponsive with connections spiking up but by the time you go in, all is well? The following article will show you how to install and configure a SQL job that will send you email alerts includ…
I have a large data set and a SSIS package. How can I load this file in multi threading?
This video shows, step by step, how to configure Oracle Heterogeneous Services via the Generic Gateway Agent in order to make a connection from an Oracle session and access a remote SQL Server database table.
This video shows how to set up a shell script to accept a positional parameter when called, pass that to a SQL script, accept the output from the statement back and then manipulate it in the Shell.

856 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question