Jim Dudley
Registered User.
- Local time
- Today, 09:49
- Joined
- Feb 16, 2012
- Messages
- 81
I have a query that worked using the "Switch" option in the Pivot Statement.
I needed to ensure that if in some instances there was no data available in a given Selection of records for one of the fields the Pivot would create, that the query not crash but return a null or "0" value in that field.
To accomplish that, I have added an "Iif" statement to the query.
Issue:
I get an error now that their is a data mismatch in the query criteria.
SQL:
TRANSFORM Count(tmp_PA_Att_Range.Type) AS CountOfType
SELECT tmp_PA_Att_Range.WCode, tmp_PA_Att_Range.Type, Count(tmp_PA_Att_Range.Type) AS [Total Of Type]
FROM tmp_PA_Att_Range
GROUP BY tmp_PA_Att_Range.WCode, tmp_PA_Att_Range.Type
PIVOT Switch(IIf([Credits]=1,"1 Credit","0"),IIf([Credits]=2,"2 Credits","0"),IIf([Credits]=3,"3 Credits","0"),IIf([Credits]>=4,"4 or more Credits","0"));
Access 2010, Windows 7.
Skill Level - SQL beginner
Any suggestions or sample query code that works for this would be appreciated.
Thank you.
Jim
I needed to ensure that if in some instances there was no data available in a given Selection of records for one of the fields the Pivot would create, that the query not crash but return a null or "0" value in that field.
To accomplish that, I have added an "Iif" statement to the query.
Issue:
I get an error now that their is a data mismatch in the query criteria.
SQL:
TRANSFORM Count(tmp_PA_Att_Range.Type) AS CountOfType
SELECT tmp_PA_Att_Range.WCode, tmp_PA_Att_Range.Type, Count(tmp_PA_Att_Range.Type) AS [Total Of Type]
FROM tmp_PA_Att_Range
GROUP BY tmp_PA_Att_Range.WCode, tmp_PA_Att_Range.Type
PIVOT Switch(IIf([Credits]=1,"1 Credit","0"),IIf([Credits]=2,"2 Credits","0"),IIf([Credits]=3,"3 Credits","0"),IIf([Credits]>=4,"4 or more Credits","0"));
Access 2010, Windows 7.
Skill Level - SQL beginner
Any suggestions or sample query code that works for this would be appreciated.
Thank you.
Jim
Last edited: