?
Solved

Group By Question

Posted on 2008-06-09
2
Medium Priority
?
229 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
2 Comments
 
LVL 39

Accepted Solution

by:
appari earned 2000 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

Get free NFR key for Veeam Availability Suite 9.5

Veeam is happy to provide a free NFR license (1 year, 2 sockets) to all certified IT Pros. The license allows for the non-production use of Veeam Availability Suite v9.5 in your home lab, without any feature limitations. It works for both VMware and Hyper-V environments

Question has a verified solution.

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

Why is this different from all of the other step by step guides?  Because I make a living as a DBA and not as a writer and I lived through this experience. Defining the name: When I talk to people they say different names on this subject stuff l…
I have a large data set and a SSIS package. How can I load this file in multi threading?
This videos aims to give the viewer a basic demonstration of how a user can query current session information by using the SYS_CONTEXT function
Viewers will learn how to use the SELECT statement in SQL to return specific rows and columns, with various degrees of sorting and limits in place.
Suggested Courses

770 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