Technical Questions
 Crystal Reports Forum : Crystal Reports 9 through 2022 : Technical Questions
Message Icon Topic: Pass formula results to Stored Proc as a parameter Post Reply Post New Topic
Author Message
akwewe
Newbie
Newbie
Avatar

Joined: 22 Jan 2009
Online Status: Offline
Posts: 2
Quote akwewe Replybullet Topic: Pass formula results to Stored Proc as a parameter
    Posted: 22 Jan 2009 at 7:30pm
I have a main report that has a formula that returns the string of state codes that I captured from a Crystal Parameter.  It's named @StringOfStates. I also have this value saved to a shared stringvar, @varSTATES.  Then, I pass @varSTATES to the subreport.

The subreport datasource is the Stored Procedure below.  In the subreport I now have two parameters.  One is Pm-@varSTATES from the main report.  The other is @STATE_CODE from the SP below.

Create procedure rpt_Emergency
@STATE_CODE varchar(255)
AS
Create table #Emergency...
Insert into #Emergency...
Select ....
From ....
Where MyTable.STATE in ('VA','MD','DC')

I need to change the last line in the SP so that it pulls the value from Pm-@varSTATES instead of having ('VA','MD','DC') hard coded.

If I change the syntax to

Where MyTable.STATE in @varSTATES I get an error stating "Must declare the variable @varSTATES."  

I guess what I'm asking is 'how do I get the variable into the SP so I can reference it?'
 
Thanks!
IP IP Logged
lockwelle
Moderator
Moderator


Joined: 21 Dec 2007
Online Status: Offline
Posts: 4372
Quote lockwelle Replybullet Posted: 23 Jan 2009 at 6:15am
Its been a while since I worked with subreports, and if I recall correctly, you would replace the ('VA','MD','DC') with a SQL variable...say @STATE_CODE or some new variable if that is in use.  Then, you would link pm-@varSTATES to @State_Code.  I am pretty sure this is what is needed.
 
I might have some of the details off, but the idea is to link the variable in main report to the sql parameter in the subreport.
 
Hope this helps, and that I am not too far off.
IP IP Logged
akwewe
Newbie
Newbie
Avatar

Joined: 22 Jan 2009
Online Status: Offline
Posts: 2
Quote akwewe Replybullet Posted: 23 Jan 2009 at 8:44am

Thanks, that makes sense.  Here's what I did:

1. In the main report, under Edit>>Subreport Links, I linked @varSTATES to my subreport.  I did not check "Select data in subreport based on this field" because the SP parameter @STATE_CODES did not show in the drop-down list.
 
2. Instead, I went into the subreport, under the record selection formula and entered {?@STATE_CODE} = {?Pm-@varSTATES}.
 
When I run the main report, I'm prompted to enter the Crystal Parameter that generates varSTATES.  This is what I expect.  I selected VA, MD and DC from my drop down list multi-select list.  To confirm varSTATES looks like I expect, I have that field in my main report and it looks like I want it to - 'VA','MD','DC'.
 
However, I'm also prompted for @STATE_CODE - the parameter set-up in the stored procedure in the subreport.  Since I want the value of varSTATES to flow to this, I don't want to be prompted for it as well.  Also, the whole reason why I'm jumping through hoops to get it this way is because I need the user to enter multiple value from a drop down list (can only do with a Crystal Parameter) and then have that string sent to a stored procedure.
 
A bigger issue is that my subreport comes up blank.  Somehow the string of states isn't getting from the main report to the subreport via the linking.
 
I'm using basic syntax in the SP, just to make sure that @STATE_CODE is populating corrected.  All the SP should do is return the string of states 'VA',MD',DC'
 
Create procedure rpt_EmergencyPreparedness
@STATE_CODE varchar(255)
AS
set nocount on
 
Create table #EmergencyPreparedness (STATE char(255))
 
Insert into #EmergencyPreparedness (STATE)
Select @STATE_CODE
 
Select * from #EmergencyPreparedness
 
Drop table #EmergencyPreparedness
IP IP Logged
lockwelle
Moderator
Moderator


Joined: 21 Dec 2007
Online Status: Offline
Posts: 4372
Quote lockwelle Replybullet Posted: 23 Jan 2009 at 2:37pm
I have always linked the data, but I can understand if you don't see the field to link to.  Since I rarely use subreports, I must be missing something in how to link.
 
Since you can create stored procedures, couldn't you create a stored procedure that has the information that you need and use the data entered by the user.  If you get all the information that you need on a data line from the stored proc, you wouldn't need to mess with the subreport (more than likely).
 
It's probably the reason that I don't use subreports, everything that I need is in the main report...I only use stored procs to retrieve the data.  I am fortunate though in not being constrained by the build in Crystal Report parameter options.
 
Sorry I couldn't be of more help.
IP IP Logged
Post Reply Post New Topic
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



This page was generated in 0.032 seconds.