Solved

Group By Question

Posted on 2008-06-09
2
182 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
Comment Utility
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
Comment Utility
perfect, thanks!
0

Featured Post

Enabling OSINT in Activity Based Intelligence

Activity based intelligence (ABI) requires access to all available sources of data. Recorded Future allows analysts to observe structured data on the open, deep, and dark web.

Join & Write a Comment

Introduction In my previous article (http://www.experts-exchange.com/Microsoft/Development/MS-SQL-Server/SSIS/A_9150-Loading-XML-Using-SSIS.html) I showed you how the XML Source component can be used to load XML files into a SQL Server database, us…
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.
Familiarize people with the process of retrieving data from SQL Server using an Access pass-thru query. Microsoft Access is a very powerful client/server development tool. One of the ways that you can retrieve data from a SQL Server is by using a pa…
Via a live example combined with referencing Books Online, show some of the information that can be extracted from the Catalog Views in SQL Server.

763 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

6 Experts available now in Live!

Get 1:1 Help Now