- Moderator
- #1
I'm attempting to write a Pivot table (I have some reports that I am currently doing pivot tables with ASP code, and it's messy)... but I'm having an issue with putting in a WHERE clause.
Here's an example.....
... it does NOT like that "Where" clause... but I only need results for that one project ID.... (or, a selected project ID).....
Any thoughts on the syntax for adding a WHERE to a pivot?
Just my 2¢
"What the captain doesn't realize is that we've secretly replaced his Dilithium Crystals with new Folger's Crystals."
--Greg
Here's an example.....
Code:
SELECT Project.ProjectID, Location.LocationName,
[Sample].CollectionDate,
Analyte.AnalyteName,
Results.SignField,
Results.Result
FROM Location INNER JOIN ((
Analyte INNER JOIN
Analysis
ON Analyte.AnalyteID = Analysis.AnalyteID) INNER JOIN (((
Project INNER JOIN
Timeslips
ON Project.ProjectID = Timeslips.ProjectID) INNER JOIN (
COC INNER JOIN (
[Sample] INNER JOIN
SeriesSample
ON [Sample].SampleID = SeriesSample.SampleID)
ON COC.COCID = [Sample].COCID)
ON Timeslips.TimeslipsID = COC.TimeslipsID) INNER JOIN
Results
ON SeriesSample.SeriesSampleID = Results.SeriesSampleID)
ON Analysis.AnalysisID = Results.AnalysisID)
ON Location.LocationID = [Sample].LocationID
PIVOT (
SUM (Results.Result)
FOR AnalyteName IN ([Benzene],[Toluene],[Ethyl Benzene],[Xylenes],[MTBE],[GRO],[DRO])
)
WHERE Project.ProjectID=15
... it does NOT like that "Where" clause... but I only need results for that one project ID.... (or, a selected project ID).....
Any thoughts on the syntax for adding a WHERE to a pivot?
Just my 2¢
"What the captain doesn't realize is that we've secretly replaced his Dilithium Crystals with new Folger's Crystals."
--Greg