Skip to Content

Archived discussions are read-only. Learn more about SAP Q&A

Passing a table-field value in Crystal to a Store Procedure in SQL Server

I have been checking all over the interenet via searches and although some seem to come close to this, its still not what I want.

Essentially I need to pass value from Table-Field record (for each record read/selected) via a paramete to a Stored Procedure(SP) in SQL Server 2205/2008. I do NOT want to be prompted for a value for this parameter each time the report is run, simple pass the value in which will be used along with other select criteria to bring back one value for the report to use in a calcuation per record.

The value of the parameter is a date, but I understand it would be better to pass it in as a varchar(8) - 'YYYYMMDD' - and then reconvert it inside the SP, as follows:

In Crystal Reports 2008 SP3, I have a formula defined as,


and essential just want to pass this to the SP below ... i.e. trans_date ---> @strTransDate

I then link the key fields [EXCH_RATE_TABLE_NAME] and [TRANS_CCY_CODE] to other tables in the Database Expert, and put [EXCH_RATE_AMT] on the report and use it to calculate what I want.

This works fine when the prompt comes up and I put in a proper date, but I don't what it to prompt, but simple pass the F1ARS_STMT_WS_TRAN.TRANS_DATEI in via the fornula/parameter and let teh SQL do the rest for each record selected..


CREATE PROCEDURE [dbo].sp_GET_EXCH_RATE_AMT (@strTransDate varchar(8)) --use format 'YYYYMMDD' to represent the date as a string.

-- Add the parameters for the stored procedure here

-- @TransDate datetime = now


declare @TransDate datetime

set @TransDate = CONVERT(DATETIME, @strTransDate, 112)


-- SET NOCOUNT ON added to prevent extra result sets from

-- interfering with SELECT statements.


-- Insert statements for procedure here









AND [START_DATEI] <= @TransDate







Thanks for any help. Can't tell the headache this has caused my both literally and figuratively.



I moved your post to the Report Design forum. Lots of SQL help in here...

I believe the problem is due to you using a Parameterized Stored Procedure. The first thing CR has to do is connect to your DB source which requires the date parameter before it can run the query to add the date filter, it's the SP that is prompting for the parameter. Therefore the report has not run so it can't get the field value from the report until you fill in the info for the SP. Catch 22 problem.... Which came first, the Chicken or the Parameter....

The report will work as you have noted but I don't know of anyway to refresh unless parameter is filled in again....

Jason has a lot of great solutions when it comes to these dilemmas, Possibly using a Command Object may help but I believe you will still run into the same issue....

Only way I can think of is to not use a parameter in the SP and let CR do the filtering client side. Of course this means all data is coming back to the client PC as you are likely trying to find a work around for.

Thank you


0 View this answer in context
Not what you were looking for? View more on this topic or Ask a question