Should I assume you made a typo for record 4 (there is one field with a zero)? I cannot see how this could ever be done in one step, since as I mentioned, you cannot exclude a field based on its data or lack thereof. Perhaps someone else will correct me on that. Try this:
Go to sql view of a new query and paste this then save as "qrySomeFields2"
Code:
SELECT tblSomeFields.ID, tblSomeFields.Name, tblSomeFields.Address, tblSomeFields.Age, tblSomeFields.ddrram AS TypeQty, "ddrram" AS TypeFld FROM tblSomeFields WHERE (((tblSomeFields.Name)="Shyam") AND ((tblSomeFields.ddrram)<>0))
UNION ALL SELECT tblSomeFields.ID, tblSomeFields.Name, tblSomeFields.Address, tblSomeFields.Age, tblSomeFields.sdram AS TypeQty, "sdram" AS TypeFld FROM tblSomeFields WHERE (((tblSomeFields.Name)="Shyam") AND ((tblSomeFields.sdram)<>0))
UNION ALL SELECT tblSomeFields.ID, tblSomeFields.Name, tblSomeFields.Address, tblSomeFields.Age, tblSomeFields.hdd AS TypeQty, "hdd" AS TypeFld FROM tblSomeFields WHERE (((tblSomeFields.Name)="Shyam") AND ((tblSomeFields.hdd)<>0))
UNION ALL SELECT tblSomeFields.ID, tblSomeFields.Name, tblSomeFields.Address, tblSomeFields.Age, tblSomeFields.mouse AS TypeQty, "mouse" AS TypeFld FROM tblSomeFields WHERE (((tblSomeFields.Name)="Shyam") AND ((tblSomeFields.mouse)<>0))
UNION ALL SELECT tblSomeFields.ID, tblSomeFields.Name, tblSomeFields.Address, tblSomeFields.Age, tblSomeFields.keyboard AS TypeQty, "keyboard" AS TypeFld FROM tblSomeFields WHERE (((tblSomeFields.Name)="Shyam") AND ((tblSomeFields.keyboard)<>0));
Do the same for a new query, paste and save as "qrySomeFieldsCrossTab"
Code:
TRANSFORM Count(qrySomeFields2.[TypeQty]) AS CountOfTypeQty
SELECT qrySomeFields2.[ID], qrySomeFields2.[Name], qrySomeFields2.[Address], qrySomeFields2.[Age]
FROM qrySomeFields2
GROUP BY qrySomeFields2.[ID], qrySomeFields2.[Name], qrySomeFields2.[Address], qrySomeFields2.Age
PIVOT qrySomeFields2.[TypeFld];
I think this will work regardless of which fields are returned when you supply a name as criteria. However, I cannot eliminate the "mouse" column because there IS a value related to the name, using the data you supplied.
ID |
Name |
Address |
Age |
ddrram |
hdd |
mouse |
4 |
Shyam |
dddddd |
45 |
1 |
1 |
|
6 |
Shyam |
dddddd |
45 |
1 |
1 |
1 |