[Expand]General Information
[Expand]WinForms Controls
[Expand]ASP.NET Controls and MVC Extensions
[Expand]ASP.NET Bootstrap Controls
[Expand]ASP.NET Core Bootstrap Controls
[Expand]WPF Controls
[Expand]Xamarin Controls
[Expand]Windows 10 App Controls
[Expand]Office File API
 [Expand]Product Information
 [Expand]Getting Started with DevExpress Reporting
 [Expand]Creating Popular Reports
 [Collapse]Detailed Guide to DevExpress Reporting
   Introduction to Banded Reports
  [Expand]Providing Data to Reports
  [Expand]Using Report Controls
  [Collapse]Shaping Report Data
   [Expand]Data Filtering
   [Expand]Grouping and Sorting
   [Expand]Shaping Data using Expression Bindings
   [Expand]Shaping Data using Legacy Data Bindings
   [Expand]Using Calculated Fields
   [Collapse]Using Report Parameters
     Parameters Overview
     Creating Multi-Value and Cascading Report Parameters
     Requesting and Passing Report Parameter Values
     Creating Custom Report Parameters
     Query Parameters
   Laying out Dynamic Report Contents
  [Expand]Customizing Appearance
  [Expand]Adding Navigation
  [Expand]Providing Interactivity
  [Expand]Adding Customary Information
  [Expand]Merging Reports
  [Expand]Using Expressions
  [Expand]Storing and Distributing Reports
  [Expand]Reporting API
 [Expand]Visual Studio Report Designer
 [Expand]Creating End-User Reporting Applications
 [Expand]API Reference
[Expand]Report and Dashboard Server
[Expand]eXpressApp Framework
[Expand]CodeRush Classic
[Expand]Cross-Platform Core Libraries
[Expand]Tools and Utilities
 End-User Documentation
This documentation page describes implementations made in our v17.2 release cycle. To learn about functionality shipping with v18.1, navigate to our updated help file experience at docs.devexpress.com. Learn More

Query Parameters

This document provides general information on query parameters and describes common ways of utilizing parametrized SQL queries to filter data on the data source level.

Expanded Query Parameters Overview

A query parameter holds an external value that is inserted into an SQL statement before query execution. This value can be either static or dynamically generated by an associated expression.

The query parameter value is inserted into the resulting SQL query string in the "@QueryParameterName" placeholder's position.

In XtraReports, query parameters are used in the following scenarios:

  • When filtering report data on the data source level using the Query Builder.

    The Query Builder helps you construct SQL queries when creating a new data-bound report or binding an existing report to an SQL data source,

    ... or when adding queries to an existing SQL data source or editing existing queries.

    You can filter the constructed queries using query parameters. Press the Edit Parameters... button to invoke the Query Parameters dialog.

    Press the Filter... button to invoke the Filter Editor and filter data using the created query parameters.

    The criteria based on the specified query parameters are added as an SQL statement's WHERE part.

    Refer to the Filtering Data at the Data Source Level topic for details on filtering using query parameters.

  • When binding a report to a stored procedure provided by an SQL data source.

    The Report Wizard, as well as the Data Source Wizard, include the Create a query or select a stored procedure page. If you select a stored procedure, the wizard creates a query parameter for each procedure parameter and allows you to configure the query parameters in the next Configure query parameters and preview the result page.

You can access query parameters using the SqlQuery.Parameters property of the query the report's SqlDataSource component exposes. These parameters include the ones you created within the Query Builder or that were generated for the data source's stored procedure. You can also access the query’s filter string using the SelectQuery.FilterString property. This filter string includes the filter that you specified in the Query Builder.

You can add new query parameters in the Query Parameters dialog and modify the filter within the Filter Editor.

Expanded Configure Query Parameters

The following properties are available for each query parameter:

  • Name - specifies the parameter's name.

  • Type - specifies the parameter value's data type.

  • Expression - determines whether the actual parameter value is static or generated dynamically.

  • Value - determines the query parameter's actual value. If the Expression option is enabled, the actual parameter value is produced dynamically by calculating an associated expression. This is useful when you map the query parameter value to the report parameter value. Refer to the Provide the Query Parameter Value document section for more information.

Expanded Provide the Query Parameter Value

Below, you can see how a value is specified for a query parameter within the Data Source Wizard's page. You can also specify query parameter values in the Report Wizard or the Query Parameters dialog in the same way.

  • Specifying a static value

    Choose a query parameter's value type and set a static value to the Value property according to the selected type.

  • Providing a dynamic value

    Activate the Expression checkbox for a parameter.

    The following three options are used to dynamically calculate the parameter's actual value:

    • Create a complex expression by expanding the Value property's drop-down list and selecting Expression Editor.

      Construct an expression in the invoked Expression Editor.

    • Map a new report parameter to a query parameter by expanding the Value property's drop-down list and selecting New Report Parameter.

      Specify report parameter settings in the invoked Report Parameter dialog. Remember to specify the report parameter type according to the type of the corresponding query parameter. Click OK to exit the dialog.

    • Map a report parameter that already exists in a report to a query parameter by expanding the Value property's drop-down list and selecting the parameter you want to use. An appropriate expression string is generated automatically.

Expanded Pass a Multi-Value Parameter Value to a Query

You can map multi-value parameters to query parameters. For instance, the following query selects the orders whose IDs can be found within the values the @OrderID query parameter provides.

Expanded Pass a Multi-Value Report Parameter Value to a Stored Procedure

You cannot pass a multi-value parameter value to a stored procedure directly. Use the Join() expression function to convert the array of parameter values to a string if you use MS SQL Server, MySQL or Oracle database systems.

Below are examples of how to get parameter values from the passed string within a stored procedure.

  • MS SQL Server

    Split the string the Join() function returns into an array within the stored procedure.

    Note that you can use the STRING_SPLIT function in MSSQL server 2016 and later.

    You can also implement a stored procedure with a User Defined Table Type parameter. In this instance, use the CreateTable() expression function to prepare a table from values of several multi-value parameters.

    The following code demonstrates how to implement a stored procedure that gets values from the table the CreateTable() function produces:

  • Oracle

    The following code demonstrates how to implement an Oracle-specific stored procedure that takes a string of parameters:

  • MySQL

    The following code demonstrates how to implement a MySQL-specific stored procedure that takes a string of parameters:

Is this topic helpful?​​​​​​​