lkbree51
Apr 19 2012, 09:53 AM
Good morning
In the Crosstab Query SQL listed below...how can I get it to show 0 (Zero) if there is no data for that day of the week?
TRANSFORM Sum(qryTransactionsWeekly.Loads) AS SumOfLoads
SELECT qryTransactionsWeekly.FirstDayofWeek, qryTransactionsWeekly.LastDayofWeek, Sum(qryTransactionsWeekly.Loads) AS TotalLoads
FROM qryTransactionsWeekly
GROUP BY qryTransactionsWeekly.FirstDayofWeek, qryTransactionsWeekly.LastDayofWeek
ORDER BY qryTransactionsWeekly.FirstDayofWeek DESC
PIVOT qryTransactionsWeekly.TWeekday In ("Sunday","Monday","Tuesday","Wednesday","Thursday","Friday","Saturday");
Thanks in advance
Larry
Jeff B.
Apr 19 2012, 10:00 AM
A couple of approaches ...
1. Have you looked into using the Nz() function?
2. Have you created a set of 'placeholder' values (e.g., Monday, 0, Tuesday, 0, ...) and joined to that?
Good luck!
arnelgp
Apr 19 2012, 10:03 AM
CODE
TRANSFORM Sum(qryTransactionsWeekly.Loads) AS SumOfLoads
to:
CODE
TRANSFORM Sum(NZ(qryTransactionsWeekly.Loads, 0)) AS SumOfLoads
RAZMaddaz
Apr 19 2012, 10:24 AM
The Sum needs to be in the inside and the Nz the outside. Like the following:
CODE
TRANSFORM Nz(Sum(qryTransactionsWeekly.[Loads]), 0) AS SumOfLoads
lkbree51
Apr 19 2012, 10:58 AM
Thanks to the 3 of you for your replies
That got my zero if there is no data...but it has taken the format off as well. On one of them I need it to show as a Fixed number with 2 (two) decimal places like 12.25
Thanks again
Larry
Jeff B.
Apr 19 2012, 11:06 AM
Larry
"Wrap" that with a Format() expression.
arnelgp
Apr 19 2012, 11:07 AM
this will format your number to 2 decimal places:
CODE
TRANSFORM FormatNumber(Nz(Sum(qryTransactionsWeekly.[Loads]), 0)) AS SumOfLoads
or
CODE
TRANSFORM Format(Nz(Sum(qryTransactionsWeekly.[Loads]), 0), "General Number") AS SumOfLoads
lkbree51
Apr 19 2012, 11:16 AM
Thanks to everyone
The first one in arnelgp's reply did it.
Thanks
Larry...
arnelgp
Apr 19 2012, 11:36 AM
From Jeff and Larry, we are happy to be of helped to you.
This is a "lo-fi" version of our main content. To view the full version with more information, formatting and images, please
click here.