0

I would like to have a report run on the entire previous month if no parameter values are passed through to the report. How do i do this?

Another option would be to have it load into the previous month by default and then when refreshed, new parameters for dates can be selected.

Is there a way to do either of these?

This is my command window. My date paramter selects the SQL code.

select cc.NM, dst.DSCRPTN, count(*)
from DST_SUBMITTION dsts , PATIENT p, DRUG_SCREEN_TEST dst, CARE_CENTER cc
where dsts.PTNT_ID = p.PTNT_ID
and   p.CC_ID = cc.CC_ID
and   dsts.DST_ID = dst.DST_ID
and   date(APNTMNT_DT) >=  date({?startDt})
and   date(APNTMNT_DT) <=  date({?endDt})
and dsts.STS_CD in ('A', 'I')
group by cc.NM, dsts.DST_ID;

3 Answers 3

1

You can do this entirely in your SQL. Use the null coalescing operator, then calculate your default if no value is supplied. Something like...

DATE >= ISNULL(?StartDate, DATEADD(m,-1,DATEADD(mm, DATEDIFF(m,0,GETDATE()), 0)))
AND DATE <= ISNULL(?EndDate, DATEADD(d,-1,DATEADD(mm, DATEDIFF(m,0,GETDATE()),0)))
Sign up to request clarification or add additional context in comments.

6 Comments

So looking at my query above, how would i go about this approach. Where would i put the code you wrote into that query?
On lines 6 and 7 of your query. You'll need to adjust it to fit. I'm using TSQL, it looks like you might be using something else, but the principal should be the same.
Will this handle the case where it isnt NULL? Say they enter date values it should use those values
That's the idea. The ISNULL function returns the first argument, if present, else the second. So put your user entered parameter first, then, if that's null, the "default" second argument will be used. This is a very handy technique that gets you out of tons of trouble.
This actually cant work because i cannot use an optional parameter when using the command SQL
|
0

Create a parameter in crystal report as bellow and make "optional prompt" is TRUE. In selection export condition apply this type of formula.

if  hasvalue({?Date parameter}) then 
{table.Date} <= {?Date parameter}
else 
{table.Date} <= DateAdd ("m", -1, CurrentDate)

by this if nothing is selected in the parameter you will get the previous month result..

2 Comments

What do i use the selection expert with? Like what table value?
ok.. if u r using command then use the field which is having the date value instead of {table.Date}.
0

I would set up a formula to determine if the parameter is null. Then replace every instance of the parameter in your report with the new formula. Something like:

If HasValue({DateParameter})
Then DateAdd ("m", -1, CurrentDate)
Else {Parameter}

2 Comments

Ah, you mean a SQL parameter. That's less of a Crystal Reports question and more of a SQL-based question. I'll update your question to include that command and a [SQL] tag so you can get some more eyes on this
Yea, SQL parameter depending on the crystal reports user input parameters

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.