• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 292
  • Last Modified:

Pivot on weekday

Experts,
The query belows works but needs some help. I need this such that I can generate a report that prints M - F across the top and places the control OnTimeScrap under the appropriate day. I've tried transform and pivot but I could never gert the syntex correct, if it is even the right way to go.

SELECT tblSupervisorReporting.ProductionDate, tblLineSupervisors.SurpevisorLN, tblLineCode.LineCodeDescription, tblLineSupervisors.Shift, tblSupervisorReporting.OnTimeScrap
FROM tblShift INNER JOIN (tblLineCode INNER JOIN (tblLineSupervisors INNER JOIN tblSupervisorReporting ON tblLineSupervisors.SupervisorID = tblSupervisorReporting.SupervisorID) ON tblLineCode.LineCodeID = tblLineSupervisors.LineCodeID) ON tblShift.ShiftID = tblLineSupervisors.Shift
WHERE (((tblSupervisorReporting.ProductionDate) Between [Enter Beginning Date] And [Enter Ending Date]) AND ((tblLineSupervisors.Active)=Yes));
0
Frank Freese
Asked:
Frank Freese
  • 2
  • 2
1 Solution
 
Patrick MatthewsCommented:
SELECT Format(tblSupervisorReporting.ProductionDate, "ddd") AS Wkday, tblLineSupervisors.SurpevisorLN, tblLineCode.LineCodeDescription, tblLineSupervisors.Shift, tblSupervisorReporting.OnTimeScrap
0
 
Frank FreeseAuthor Commented:
How do I incorporate this into my query?
0
 
Patrick MatthewsCommented:
Use that new SELECT clause instead of the old one, and then use the Crosstab Wizard to build a corsstab
based on that query you just made.
0
 
Frank FreeseAuthor Commented:
I replaced my Select statement with yours as follows:

SELECT Format(tblSupervisorReporting.ProductionDate, "ddd") AS Wkday, tblLineSupervisors.SurpevisorLN, tblLineCode.LineCodeDescription, tblLineSupervisors.Shift, tblSupervisorReporting.OnTimeScrap
FROM tblShift INNER JOIN (tblLineCode INNER JOIN (tblLineSupervisors INNER JOIN tblSupervisorReporting ON tblLineSupervisors.SupervisorID = tblSupervisorReporting.SupervisorID) ON tblLineCode.LineCodeID = tblLineSupervisors.LineCodeID) ON tblShift.ShiftID = tblLineSupervisors.Shift
WHERE (((tblSupervisorReporting.ProductionDate) Between [Enter Beginning Date] And [Enter Ending Date]) AND ((tblLineSupervisors.Active)=Yes));

I t worked.

I then created a cross tab query using the above query:

TRANSFORM Count(qryByDateOnTimeSupervisors.OnTimeScrap) AS CountOfOnTimeScrap
SELECT qryByDateOnTimeSupervisors.SurpevisorLN, qryByDateOnTimeSupervisors.LineCodeDescription, qryByDateOnTimeSupervisors.Shift
FROM qryByDateOnTimeSupervisors
GROUP BY qryByDateOnTimeSupervisors.SurpevisorLN, qryByDateOnTimeSupervisors.LineCodeDescription, qryByDateOnTimeSupervisors.Shift
PIVOT qryByDateOnTimeSupervisors.Wkday;

I ran the query and received the following error:

The Microsoft Jet database engine does not recognize "Enter Beginning Date"  as a valid field name or expression".
0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

Join & Write a Comment

Featured Post

Cloud Class® Course: SQL Server Core 2016

This course will introduce you to SQL Server Core 2016, as well as teach you about SSMS, data tools, installation, server configuration, using Management Studio, and writing and executing queries.

  • 2
  • 2
Tackle projects and never again get stuck behind a technical roadblock.
Join Now