Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations SkipVought on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Calling Commands in Formula Slows report dramatically

Status
Not open for further replies.

pcollins1

Technical User
Jun 19, 2002
72
0
0
US
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:

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.
 
Is your main report based on a Command if so embed the logic of your date parameters into the main command SQL.

When the report is parses SQL to database the only filter going to DB is
{IMITMIDX.item_weight} <> 1.00

All the other filters are being executed locally on report PC, that is why slow. When you hard code dates they are parsed to DB too.

Best solution is to redesign report using a Command and use your auto dat parameters in that.
Ian
 
My guess is that the command is not being used anywhere else, so until you use it in this formula, Crystal is ignoring the command. You would probably get the same performance hit if you simply put the field onto a band in the report, so it is probably not something specific to that formula. In most cases, any time you mix tables with commands you will slow things down.

Ken Hamady, On-site Custom Crystal Reports Training & Consulting
Public classes and individual training.
Guides to Formulas, Parameters, Subreports, Cross-tabs, VB, Tips and Tricks
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top