Update how-to-use-local-variables-in-a-sql-query-used-by-the-sqldatas… (#1496)

* Update how-to-use-local-variables-in-a-sql-query-used-by-the-sqldatasource-component.md

* Update how-to-use-local-variables-in-a-sql-query-used-by-the-sqldatasource-component.md

---------

Co-authored-by: Dimitar Nikolov <dnikolov@progress.com>
This commit is contained in:
Todor Arabadzhiev 2024-09-25 17:51:58 +03:00 коммит произвёл GitHub
Родитель e83470355e
Коммит d9244ac808
Не найден ключ, соответствующий данной подписи
Идентификатор ключа GPG: B5690EEEBB952194
1 изменённых файлов: 11 добавлений и 13 удалений

Просмотреть файл

@ -1,6 +1,6 @@
---
title: How to use local variables in a SQL query used by the SqlDataSource component
description: How to create local variables in a SQL query used by the SqlDataSource component.
title: Add local variables to SQL query used by the SqlDataSource
description: "Learn how to create local variables in a SQL query used by the SqlDataSource component."
type: how-to
page_title: How to implement local variables in a SQL query used by the SqlDataSource component
slug: how-to-use-local-variables-in-a-sql-query-used-by-the-sqldatasource-component
@ -24,35 +24,33 @@ res_type: kb
## Description
In this article, we will explain how to use local variables in a SQL query used by the SqlDataSource component.
In this article, we will explain how to use local variables in an SQL query used by the SqlDataSource component.
Sample SQL query:
```sql
````sql
Declare @localVariable varchar(max)
Set @localVariable='SELECT * FROM MYTABLE'
Exec(@localVariable)
```
````
- If the above is set as SQL text, the [SqlDataSource Wizard]({% slug telerikreporting/designing-reports/connecting-to-data/data-source-components/sqldatasource-component/overview %}-wizard) will return an error like:
- If the above is set as SQL text, the [SqlDataSource Wizard]({%slug telerikreporting/designing-reports/report-designer-tools/desktop-designers/tools/data-source-wizards/sqldatasource-wizard/overview%}) will return an error like:
```
The variable name '@localVariable' has already been declared. Variable names must be unique within a query batch or stored procedure.
```
`The variable name '@localVariable' has already been declared. Variable names must be unique within a query batch or stored procedure.`
## Solution
On configuring a SqlDataSource component you can map SQL parameters to report parameters - SqlDataSource Wizard [step 4]({% slug telerikreporting/designing-reports/connecting-to-data/data-source-components/sqldatasource-component/overview %}-wizard).
On configuring a SqlDataSource component you can map SQL parameters to report parameters - [SqlDataSource Wizard - step 4]({%slug telerikreporting/designing-reports/report-designer-tools/desktop-designers/tools/data-source-wizards/sqldatasource-wizard/overview%}).
SQL queries relying on local variables can be turned into **stored procedures**.
The .NET provider will not consider the internally declared SQL parameters as procedure's parameters.
The .NET provider will not consider the internally declared SQL parameters as the procedure's parameters.
## Notes
The syntax of the SQL query must be considered with the specification of the selected .NET data provider. It is the provider that interprets the SQL query and provides information what ADO<span>.</span>NET classes to be used for retrieving data. If the .NET data provider recognizes the local variables as SQL parameters, they will be listed for mapping by the SqlDataSource Wizard, which will result in an error on executing the SQL query.
The syntax of the SQL query must be considered with the specification of the selected .NET data provider. It is the provider that interprets the SQL query and provides information on what ADO.NET classes are to be used for retrieving data. If the .NET data provider recognizes the local variables as SQL parameters, they will be listed for mapping by the SqlDataSource Wizard, which will result in an error in executing the SQL query.
## See Also
[Using Parameters with the SqlDataSource component.]({%slug telerikreporting/designing-reports/connecting-to-data/data-source-components/sqldatasource-component/using-parameters-with-the-sqldatasource-component%})
* [Using Parameters with the SqlDataSource component.]({%slug telerikreporting/designing-reports/connecting-to-data/data-source-components/sqldatasource-component/using-parameters-with-the-sqldatasource-component%})