Create Custom SQL Query Reports as .NET Classes
Copyright © 2019 EarthSoft, Inc • Modified: 18 Feb 2019
The EQuIS API provides the ability to create custom reports as .NET classes. .NET class reports provide the most flexibility in computation and output (e.g. producing pre-formatted Excel workbooks). However, in many cases, you may just want to export some data as a table for further processing. As an alternative to writing a .NET class, you can publish a SQL query as a custom report by following these instructions.
1.Compose and test the query in a SQL editor (e.g. SQL Server Management Studio or SQL Developer). Compose the query using the EQuIS SQL Form.
2.Save the query as a *.sql file on your local machine.
3.Publish the *.sql file as a report using the Report Publisher. The report will show up as a class report (EQuIS uses the EarthSoft.Common.Reports.SqlQueryReport class to run the report).
Note: For any type of report, ST_REPORT.REPORT_NAME should not end with text identical to standard EarthSoft report names, but instead follow report naming conventions.
Here are additional points to consider when composing a query to be used as an EQuIS report.
•Only database-level security (DLS) users or application-level security (ALS) administrators may publish reports. ALS users who are not administrators may not publish a report.
•The SQL query must use the appropriate syntax for the database you are using (Oracle Database or Microsoft SQL Server). Much of the ANSI SQL Standard is supported by both database systems, but some syntax is database-specific.
•The SQL query must be safe, which means that it may only contain SELECT statements; it may not contain INSERT, UPDATE, DELETE, DROP, etc. If the query is unsafe, it will not be executed when the report runs.
•Define parameters in your query (e.g. " ... sys_loc_code = @sys_loc_code ... "). The Report Publisher will automatically recognize parameters
oYou may specify parameter metadata (e.g. display type. data source, etc.) within the Report Publisher or in the ST_REPORT_PARAMETER table (after the report is published).
oThe following parameters will be recognized, and default metadata will be provided.
•When running the published report in EQuIS Professional, the parameter will not be shown to the user, but will be automatically set to the currently selected facility.
•When running the published report in EQuIS Enterprise, the parameter will be shown and the user will be prompted to select from the facilities that he or she has permission to.
▪@user_id (automatically set to the current user)
▪@start_date (automatically set as a date chooser with a default date of one year ago today)
▪@end_date (automatically set as a date chooser with a default date of today)
▪@cas_rn (automatically set as a drop-down showing CAS_RN and CHEMICAL_NAME from RT_ANALYTE
▪@sys_loc_code (automatically set as a drop-down showing SYS_LOC_CODE and LOC_NAME from DT_LOCATION)
o**EQuIS will not automatically add a @facility_id parameter to your query. If you choose to write and publish a query that does not include a @facility_id parameter, your end users may end up seeing data from facilities they do not have permission to. You should always include a @facility_id parameter, unless you specifically do not want it.
•SQL query reports may be used like any other report (in Professional, in Enterprise, as an EIA, etc.)