From d9244ac8088f953789ed9fc07dde3f150b25420e Mon Sep 17 00:00:00 2001 From: Todor Arabadzhiev Date: Wed, 25 Sep 2024 17:51:58 +0300 Subject: [PATCH] =?UTF-8?q?Update=20how-to-use-local-variables-in-a-sql-qu?= =?UTF-8?q?ery-used-by-the-sqldatas=E2=80=A6=20(#1496)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit * 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 --- ...ery-used-by-the-sqldatasource-component.md | 24 +++++++++---------- 1 file changed, 11 insertions(+), 13 deletions(-) diff --git a/knowledge-base/how-to-use-local-variables-in-a-sql-query-used-by-the-sqldatasource-component.md b/knowledge-base/how-to-use-local-variables-in-a-sql-query-used-by-the-sqldatasource-component.md index 57a1c2cf4..0cc54d8a0 100644 --- a/knowledge-base/how-to-use-local-variables-in-a-sql-query-used-by-the-sqldatasource-component.md +++ b/knowledge-base/how-to-use-local-variables-in-a-sql-query-used-by-the-sqldatasource-component.md @@ -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.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%})