Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Condense rows in a query 1

Status
Not open for further replies.

fishtek

Technical User
Aug 21, 2002
56
US
I have a query that returns the following with each row representing a different date in 2008:

Code:
Facility	Year	Jan	Feb	Mar	Apr
Dare County	2008	Pass	*	*	*
Dare County	2008	*	*	*	Pass
Dare County	2008	*	Pass	*	*
Dare County	2008	*	*	Fail	*

Is it possible in the query to condense the rows like so:

Code:
Facility	Year	Jan	Feb	Mar	Apr
Dare County	2008	Pass	Pass	Fail	Pass

Thanks for any help.


 
I have a query that returns the following
What is the SQL code of this query ?

Hope This Helps, PH.
FAQ219-2884
FAQ181-2886
 
Thanks PHV. The SQL code is as follows:

Code:
SELECT tblFacility.Facility, tblTesRec.[Test Date], Year([Test Date]) AS [Year], tblTesRec.Result, IIf(Month([Test Date])=1,[Result],"*") AS Jan, IIf(Month([Test Date])=2,[Result],"*") AS Feb, IIf(Month([Test Date])=3,[Result],"*") AS Mar, IIf(Month([Test Date])=4,[Result],"*") AS Apr
FROM tblFacility LEFT JOIN tblTesRec ON tblFacility.NPDES = tblTesRec.NPDES
WHERE (((Year([Test Date])) Between Year(Now()) And Year(Now())-4));
 
With questioning your current SQL, you could simply create another query with SQL of:

SQL:
SELECT Facility, [Year], Max(Jan) AS MaxOfJan, Max(Feb) AS MaxOfFeb, Max(Mar) AS MaxOfMar, Max(Apr) AS MaxOfApr
FROM YourQueryNameHere
GROUP BY Facility, [Year];

Duane
Hook'D on Access
MS Access MVP
 
What about this ?
Code:
SELECT F.Facility, Year(T.[Test Date]) AS [Year]
, Max(IIf(Month(T.[Test Date])=1,T.Result," ")) AS Jan
, Max(IIf(Month(T.[Test Date])=2,T.Result," ")) AS Feb
, Max(IIf(Month(T.[Test Date])=3,T.Result," ")) AS Mar
, Max(IIf(Month(T.[Test Date])=4,T.Result," ")) AS Apr
FROM tblFacility F INNER JOIN tblTesRec T ON F.NPDES = T.NPDES
WHERE Year(T.[Test Date]) Between Year(Now()) And (Year(Now())-4)
GROUP BY F.Facility, Year(T.[Test Date])

Hope This Helps, PH.
FAQ219-2884
FAQ181-2886
 
Thanks dhookom and PHV. Looks like it works.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top