Technical Questions
 Crystal Reports Forum : Crystal Reports 9 through 2022 : Technical Questions
Message Icon Topic: Dynamically pass parameters to a stored procedure Post Reply Post New Topic
Author Message
wshaw
Newbie
Newbie


Joined: 27 Mar 2009
Online Status: Offline
Posts: 3
Quote wshaw Replybullet Topic: Dynamically pass parameters to a stored procedure
     Posted: 30 Mar 2009 at 5:56am
I have a report (Crystal XI) that returns data about support tickets - basic info, like who opened it, closed it, etc...  Each record is another ticket, i.e. the ticket data is in the details section.
I need to add the amount of time that each ticket has been worked.  Unfortunately, that is determined by a stored procedure that takes the ticket id as a parameter.  I can't find a way to embed the stored procedure in the details section and have it automatically use a given field as it's input.
I had considered replicating the logic in the sproc in CR, but this stored procedure is absolutely hideous.  It also doesn't help that this database (SQL Server 2005, running in SQL 2000 compatibility mode) is the backend for an off the shelf ticketing application that we can't mess with too much - at least not directly.
Is anyone familiar with how to do this, or am I far too incoherent to help?
IP IP Logged
lockwelle
Moderator
Moderator


Joined: 21 Dec 2007
Online Status: Offline
Posts: 4374
Quote lockwelle Replybullet Posted: 30 Mar 2009 at 6:53am
Add the stored proc as 'table' in the report.  Under the database expert, just like adding a table, except use the Stored Procedures section.  Create a link between the ticket and the stored proc, then you can use the data from the stored proc.
 
Depending on how fast the stored proc is, it might make your report run slower as each ticket would hit the stored proc, but it would get the info that you want.
 
Hope this helped.
IP IP Logged
wshaw
Newbie
Newbie


Joined: 27 Mar 2009
Online Status: Offline
Posts: 3
Quote wshaw Replybullet Posted: 30 Mar 2009 at 7:01am
I had tried that in the past, and here's what ends up happening.

I add the sproc via the database expert, and a popup requests the parameter to be sent to the sproc, with the checkbox automatically checked for 'Set to Null'.  I set the join up correctly between the two, and refreshing the report returns no data as the parameter is set to null.  I don't want to explicitly state what the value of that parameter should be, but it seems that I either need to pick a value or set it to null in order for the report to run.
IP IP Logged
DBlank
Moderator
Moderator


Joined: 19 Dec 2008
Online Status: Offline
Posts: 9053
Quote DBlank Replybullet Posted: 30 Mar 2009 at 7:09am

I think Lockwelles suggestion implies that you remove the parameter from the SP and have it run for all the items in the DB and then you link the 2 together and you are looking for a way for the one table to run then pass the values to the stored proc each time it runs.

I have not tried this but perhaps adding a sub-report to each detail linking the ticketid in the main report to the storedproc parameter in the subreport and returning the value there. This may correctly pass each item into the stored proc allowing it to run and return a value per row at runtime. Worth a shot.
IP IP Logged
lockwelle
Moderator
Moderator


Joined: 21 Dec 2007
Online Status: Offline
Posts: 4374
Quote lockwelle Replybullet Posted: 31 Mar 2009 at 6:05am
When you add a stored proc to a report, it asks for the parameter so that it can determine the fields that the stored proc returns.  It is not the ONLY value that stored proc is going to use.  When you link the stored proc and the table, it would be like linking 2 tables.
 
I haven't tried this myself as I am either all tables or all stored proc, but it should work.
IP IP Logged
wshaw
Newbie
Newbie


Joined: 27 Mar 2009
Online Status: Offline
Posts: 3
Quote wshaw Replybullet Posted: 31 Mar 2009 at 6:25am
Thanks dblank and lockwelle.  I ended up making it a non-parameterized sproc and linking it to the other table in the report, which is just simpler, and this is something of a throwaway report anyway.  It also has the added benefit of working, which is nice :).  Thanks guys!
IP IP Logged
Printable version Printable version

Forum Jump
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot delete your posts in this forum
You cannot edit your posts in this forum
You cannot create polls in this forum
You cannot vote in polls in this forum