Solved: Crosstab SQL syntax required
Hey guys,
Not strictly a VBA question, but this will be leveraged via VBA on an Access db from Excel...
I have a crosstab SQL query that looks liket this:
Code:
TRANSFORM Sum(tblInvDetail.Amount) AS SumOfAmount
SELECT tblSuppliers.SupplierName, tblInvoices.InvDate, tblInvoices.InvNumber
FROM tblExpGroups INNER JOIN ((tblSuppliers INNER JOIN tblInvoices ON tblSuppliers.SupplierID = tblInvoices.SupplierID)
INNER JOIN (tblExpType INNER JOIN tblInvDetail ON tblExpType.ExpTypeID = tblInvDetail.ExpTypeID) ON tblInvoices.InvID = tblInvDetail.InvID)
ON tblExpGroups.ExpGroupID = tblExpType.ExpGroupID
WHERE (((tblInvoices.InvDate)>=#2/1/2006# And (tblInvoices.InvDate)<=#2/5/2006#) AND ((tblInvDetail.DeptID)=150))
GROUP BY tblSuppliers.SupplierName, tblInvoices.InvDate, tblInvoices.InvNumber, tblInvDetail.DeptID
ORDER BY tblExpGroups.ExpGroupName
PIVOT tblExpGroups.ExpGroupName;
Problem is that it is only returning my columns for tblExpType.ExpGroupName where there is actualy data in one of the records. This makes sense, and normally is what most people would want, but there are only 13 records in that table, and I need them all to show every time. If nothing is in the column, then fill it with blank or zeros, I don't care, but I need those headers. Reason for the above is that I'm trying to drop it into a static Excel table, and I don't want my data always shifting.
Is there a statement in SQL that you can add to always show all columns in a crosstab? http://vbaexpress.com/forum/images/smilies/102.gif