Hi,
I've a (lookup) table with 10 names/records. Each day in a second (history) table I add values for each of the 10 names. Sometimes however, there is no data for one of these names, so no record is added to the historytable. When creating a crosstabquery, sometimes this means that records that have no values, will not be listed as headers. To overcome this, I've used the IN statement in the crosstab, which lists the names.
My question is:
Can this be done dynamically? Users have the ability to add names to the lookup table and now I have to check and change the query manually.
I'll put the sql in here, but don't get confused; my dutch Access makes it a bit harsh to read
:
As said, the last line contains the names that are in the records of a lookup table.
I've a (lookup) table with 10 names/records. Each day in a second (history) table I add values for each of the 10 names. Sometimes however, there is no data for one of these names, so no record is added to the historytable. When creating a crosstabquery, sometimes this means that records that have no values, will not be listed as headers. To overcome this, I've used the IN statement in the crosstab, which lists the names.
My question is:
Can this be done dynamically? Users have the ability to add names to the lookup table and now I have to check and change the query manually.
I'll put the sql in here, but don't get confused; my dutch Access makes it a bit harsh to read
![[sad] [sad] [sad]](/data/assets/smilies/sad.gif)
TRANSFORM Sum(tbl_hist_daily_totals.[Aantal EAN]) AS [SomVanAantal EAN]
SELECT tbl_hist_daily_totals.Datum, tbl_month.key, tbl_month.maand, tbl_hist_daily_totals.jaar, IIf([tbl_hist_daily_totals]![missing]=True,"Missing","Available") AS Status, tbl_meter_opname_methode.regio, Sum(tbl_hist_daily_totals.[Aantal EAN]) AS Subtotaal, Sum(IIf([tbl_meter_opname_methode]![regio]='dco',[tbl_hist_daily_totals]![Aantal EAN],0)) AS SubtotaalDCO, Sum(IIf([tbl_meter_opname_methode]![regio]='dcw',[tbl_hist_daily_totals]![Aantal EAN],0)) AS SubtotaalDCW
FROM tbl_meter_opname_methode INNER JOIN ((tbl_hist_daily_totals INNER JOIN tbl_month ON tbl_hist_daily_totals.maand = tbl_month.key) INNER JOIN qry_maxdate_this_month ON tbl_hist_daily_totals.Datum = qry_maxdate_this_month.MaxVanDatum) ON tbl_meter_opname_methode.key = tbl_hist_daily_totals.FK_Beoogd
GROUP BY tbl_hist_daily_totals.Datum, tbl_month.key, tbl_month.maand, tbl_hist_daily_totals.jaar, IIf([tbl_hist_daily_totals]![missing]=True,"Missing","Available"), tbl_meter_opname_methode.regio, tbl_hist_daily_totals.missing
ORDER BY tbl_month.key
PIVOT tbl_meter_opname_methode.Type In ("C2000","Extern","HF","Profiel","SMS", "SMS Automatisch", "TM", "Som", "Onbekend");
As said, the last line contains the names that are in the records of a lookup table.