I have been tasked with using a 4-4-5 date scheme and have created a SQL command to query a table to calculate beginning and end date for periods. I have determined the command itself returns the result quickly, but if called from the select expert it is slow.
Here is the SQL command:
Here is the record select formula, using the command results:
If I use hard-coded dates instead of {Command.whatever}, it runs fast. And if I simply place the results in the report, it runs fast. But when I add the {Command} code to the record select formula... it bogs down.
Here is the SQL command:
Code:
declare @now datetime, @fm int, @fy int, @param int;
set @now = getdate();
set @fm = (select FiscalMonth from FiscalCalendar445 where CalendarDate = DATEADD(d, datediff(d, 0, @now), 0));
set @fy = (select FiscalYear from FiscalCalendar445 where CalendarDate = DATEADD(d, datediff(d, 0, @now), 0));
set @param = {?FiscalPeriods};
select MIN(CalendarDateNum) as begindate, MAX(CalendarDateNum) as enddate
from FiscalCalendar445
where FiscalMonth =
case
when @fm - @param > 0 then @fm - @param
when @fm - @param + 12 > 0 then @fm - @param + 12
when @fm - @param + 24 > 0 then @fm - @param + 24
else @fm - @param + 36
end
and FiscalYear = @fy - ( @param / 12 )
Here is the record select formula, using the command results:
Code:
{@QUANTITY} <> 0.00 and
{@Pounds} <> 0 and
{OEHDRHST.inv_dt} in {Command.begindate} to {Command.enddate} and
{IMITMIDX.item_weight} <> 1.00
If I use hard-coded dates instead of {Command.whatever}, it runs fast. And if I simply place the results in the report, it runs fast. But when I add the {Command} code to the record select formula... it bogs down.