Jump to content
Changes to the Jaspersoft community edition download ×
  • Calling Microsoft SQL Stored Procedures from iReport


    eongaro

    This article provides information about calling stored procedures in iReport Designer with Microsoft SQL.

    Create a Stored Procedure on Micrsoft SQL

    -- =============================================
    -- Author: author name
    -- Create date: created
    -- Description: description
    -- =============================================
    CREATE PROCEDURE ireport @parameter1 INT
    AS BEGIN
             SELECT 125 * @parameter1 AS somefield
         END
    GO
    

    This particular dummy stored procedure simply takes a parameter and multiplies it by 125. Not very useful but a good proof of concept.

    Chose plsql as the query language

    IReport_Calling_Stored_Procedures_1.JPG.ca7be4bf8a4e32f880333e08cfcf0711.JPG

    Create Parameters and Simply call the Stored Procedure by Name

    Stored_proc_query.png.ddb332e8d712ff1d6189c66169510c7d.png

    In this case, the name of the stored procedure is 'ireport' and it takes exactly one parameter. The parameter was defined with a default value expression of "2" which simply multiplies 125 by 2.

    That's it, simply use the fields in your report and the user will be prompted via parameter, the parameters might also come from LoggedinUser/role/attribute which helps tie into security models. It is also possible to save this report in the Topics folder of JasperReports server to take advantage of the Ad-Hoc engine and stored procedures.

    Note: You should disable the rows() affected message by running SET NOCOUNT ON on the SQL server

    It may be necessary to add an exclamation point after the $P, for example $P!{parameter1}.

    IReport_Calling_Stored_Procedures_1.JPG.850ff1d5bd1c612e10040c435b641943.JPG

    Stored_proc_query.png.0d57afb50f068749914ac56106e840cd.png


    User Feedback

    Recommended Comments

    There are no comments to display.



    Guest
    This is now closed for further comments

×
×
  • Create New...