Solved

Group By Question

Posted on 2008-06-09
2
192 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

PRTG Network Monitor: Intuitive Network Monitoring

Network Monitoring is essential to ensure that computer systems and network devices are running. Use PRTG to monitor LANs, servers, websites, applications and devices, bandwidth, virtual environments, remote systems, IoT, and many more. PRTG is easy to set up & use.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
set default date format in mssql to mm/dd/yyyy 22 69
Parse field in SQL View 15 99
T-SQL: Nested CASE Statements 4 25
SQL Server 2012 r2 - Sum causes too much time 5 15
This article explains how to reset the password of the sa account on a Microsoft SQL Server.  The steps in this article work in SQL 2005, 2008, 2008 R2, 2012, 2014 and 2016.
For both online and offline retail, the cross-channel business is the most recent pattern in the B2C trade space.
Via a live example, show how to extract information from SQL Server on Database, Connection and Server properties
Viewers will learn how to use the UPDATE and DELETE statements to change or remove existing data from their tables. Make a table: Update a specific column given a specific row using the UPDATE statement: Remove a set of values using the DELETE s…

863 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

Need Help in Real-Time?

Connect with top rated Experts

29 Experts available now in Live!

Get 1:1 Help Now