Search code examples
sql-serverstored-procedurescrystal-reportsparameter-passingsql-function

Crystal Reports Pass database fields as parameter for Stored Procedure


I have a Stored Procedure/SQL function that makes calculations on a specific record returning 0.00 or another DEC value. It takes the record's primary key as a parameter.

I want to implement this function/Stored procedure in Crystal Reports by passing the primary key database field for each individual record. However, when I try to do this, it requires me to manually input the id. The crystal report that I implement is grouped by the id so that there'll be a report for each record.

Is there a way I can pass a database field as a parameter for a Stored Procedure or a SQL function? Is there something similar I can use?


Solution

  • An alternative approach is to insert a subreport using the SP as its data source into the Group Header section. Pass the ID as the subreport link, so it gets used as the SP parameter.
    If you need the returned value in main report calculations, use a subreport formula to load the value into a Shared variable so it is accessible to main report formulas.

    Another option is to use a Crystal Reports UFL (User Function Library). Ken Hamady maintains a list of UFLs here. At least one of them provides a function that allows you to call a dynamic SQL statement and return a value.