Solved

Group By Question

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

Forrester Webinar: xMatters Delivers 261% ROI

Guest speaker Dean Davison, Forrester Principal Consultant, explains how a Fortune 500 communication company using xMatters found these results: Achieved a 261% ROI, Experienced $753,280 in net present value benefits over 3 years and Reduced MTTR by 91% for tier 1 incidents.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
section a string 5 52
SQL Server 2005 running VERY slowly on new hardware 22 55
Migrate SQL 2005 DB to SQL 2016 4 18
T-SQL Query 9 30
In this article we will get to know that how can we recover deleted data if it happens accidently. We really can recover deleted rows if we know the time when data is deleted by using the transaction log.
The Delta outage: 650 cancelled flights, more than 1200 delayed flights, thousands of frustrated customers, tens of millions of dollars in damages – plus untold reputational damage to one of the world’s most trusted airlines. All due to a catastroph…
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.
Using examples as well as descriptions, and references to Books Online, show the different Recovery Models available in SQL Server and explain, as well as show how full, differential and transaction log backups are performed

736 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