| Author |
Message |
JESii
Newbie
Joined: 03 Aug 2009
Location: United States
Online Status: Offline
Posts: 7
|

Topic: Passing 'dynamic' parameters to Stored Procedure Posted: 03 Aug 2009 at 1:38pm |
|
Hi... I'm having problems passing a 'dynamic' parameter to a stored procedure: the "Create" parameters seems to allow only simple data strings, and not variables or other values entered/created at run time.
The report uses a database command which simply executes a procedure:
EXECUTE MyStoredProcedure;
The procedure has two parameters: startDate and endDate, both of which are defaulted in the stored proc.
The report prompts the user for a start date and an end date (?StartDate & ?EndDate).
Right now, using the default values in the stored proc, everything is running just fine.
I want to pass these two values to the stored procedure so that when the user selects the desired date range, it passes on thru to the stored procedure.
I don't see how to pass in the values that are already entered (I don't want the user to have to enter the same dates twice). It looks like the prompt has to happen and that they will have to enter the dates twice.
Any suggestions would be most appreciated, including a definitive statement that "you can't do that" so I don't waste more time looking for an impossible solution.
In fact, I can't even get a simple test run of the parameters to work: CR complains with "Error converting data type nvarchar to datetime" (my parameters are smalldatetime types, which means only date, no time).
Cheers...jon
|
IP Logged |
|
|
|
Allany
Newbie
Joined: 03 Aug 2009
Online Status: Offline
Posts: 12
|

Posted: 04 Aug 2009 at 3:15am |
I'm a bit confused. I assume you created a report based on a stored proc and the report is giving you the 2 parameters (?StartDate & ?EndDate) as mentioned.
When you run your report it comes up with the start/end date prompt and then it fails?
|
IP Logged |
|
JESii
Newbie
Joined: 03 Aug 2009
Location: United States
Online Status: Offline
Posts: 7
|

Posted: 04 Aug 2009 at 7:25am |
|
?StartDate & ?EndDate are the standard CR variables for parameters that are prompted for by CR at the beginning of the run.
The report uses the proc and works just fine using the procs default start/end dates.
I want to pass along CR's start/end date parameter values to the proc, using:
EXECUTE MyStoredProcedure sDate, eDate;
where sDate/eDate contain the values of ?StartDate, ?EndDate.
That's what I can't see how to do...
|
IP Logged |
|
Allany
Newbie
Joined: 03 Aug 2009
Online Status: Offline
Posts: 12
|

Posted: 04 Aug 2009 at 8:31am |
Still not 100%, from experience, you should be able to just choose your start/end date from the CR run window, and then if the proc is linked to your main report, then it should accept the dates provided from the CR, as long as you don't set the dates again in the stored proc to be your defaults.
Unless you are using sub reports? Where then you would need to create 2 new functions e.g dtStart2, dtEnd2 and then link them via the subreport link.
Unless I am reading this all wrong...
|
IP Logged |
|
JESii
Newbie
Joined: 03 Aug 2009
Location: United States
Online Status: Offline
Posts: 7
|

Posted: 04 Aug 2009 at 1:20pm |
|
"just choose your start/end date from the CR run window" >> That's exactly what I did. In case you're not familiar with this feature, those values are referenced as ?StartDate & ?EndDate...
"it should accept the dates provided from the CR" >> It should/ Tell me how that happens and you've solved my problem.
Why don't you try creating a stored proc that requires a single parameter, and then use the Command option in the database expert to execute the stored proc. Then run the report, get the value of that single parameter, and then pass that parameter from the CR run window into the stored proc. Maybe that will help clarify the issue for you.
|
IP Logged |
|
DBlank
Moderator
Joined: 19 Dec 2008
Online Status: Offline
Posts: 9053
|

Posted: 04 Aug 2009 at 2:39pm |
Is there a reason you are using the COmmand function to execute the stored proc rather than just using the stored proc directly as your datasource?
If you do that, any paramters that you have set in your stored proc will be automatically created in the report and are passed to the stored proc. Edited by DBlank - 04 Aug 2009 at 2:40pm
|
IP Logged |
|
JESii
Newbie
Joined: 03 Aug 2009
Location: United States
Online Status: Offline
Posts: 7
|

Posted: 04 Aug 2009 at 3:10pm |
|
Yes, I've also used the stored proc: two issues there...
1) user gets prompted twice: once for the CR parameter and once for the SQL parameters
2) If there are defaults in the stored proc, then CR doesn't prompt for them.
|
IP Logged |
|
JESii
Newbie
Joined: 03 Aug 2009
Location: United States
Online Status: Offline
Posts: 7
|

Posted: 04 Aug 2009 at 3:11pm |
|
And actually, there's also a third issue...
In the stored proc, I define the dates as shortdatetime (mm/dd/yyyy only), but CR prompts for them as a full date/time value and there requires that the user enter hh:mm:ss as well -- doubly ugly.
|
IP Logged |
|
DBlank
Moderator
Joined: 19 Dec 2008
Online Status: Offline
Posts: 9053
|

Posted: 04 Aug 2009 at 5:58pm |
1) You only use the params that were created via the SP. Delete the ones you manually created in crystal.
2) get rid of the defaults. Sorry but crystal does not like them.
3) Let em see if Lockewelle has a suggestion for this one. I don't use SPs but rather views, he uses SPs for everything. I know you can make them a string and then convert it in the SP using a CASE but there may be a better solution.
|
IP Logged |
|
JESii
Newbie
Joined: 03 Aug 2009
Location: United States
Online Status: Offline
Posts: 7
|

Posted: 05 Aug 2009 at 4:38am |
|
Thanks; very helpful; sounds like you're saying that there is no way to pass CR params into the SP...
1)
If I do that, then I don't have the parameter values to print in the
report: i.e., it's a date range report and I like to put the the dates
somewhere in the title so that it's clear to the user what they're
looking at. I briefly considered returning the date parameters back in
each row as part of the SP so that I could use them that way, but that
does seem like rather a kludgey hack.
3) I'll be very interested to see what he has to say; thanks.
|
IP Logged |
|
|
|