Error with Parameters named "like" variables

Discussion of open issues, suggestions and bugs regarding SDAC (SQL Server Data Access Components) for Delphi, C++Builder, Lazarus (and FPC)
Post Reply
mguzman69
Posts: 3
Joined: Thu 22 Nov 2018 18:54

Error with Parameters named "like" variables

Post by mguzman69 » Fri 23 Nov 2018 17:46

Hello,

I have a problem with TMSQuery, supose this simple SQL put into a TMSQuery.SQL property

DECLARE @CLIENTE_ID INT
SET @CLIENTE_ID = :CLIENTE_ID
SELECT 'CLIENTE :'+CAST(@CLIENTE_ID AS VARCHAR)

When Set Active the component, get thiw message :

The name of variable @CLIENTE_ID has already been declared. The names of variables must bue unique on every batch os queries or stored procedures

Do you know a way to fix this error.

I have used this kind of querys years ago with BDE, TADOQuery, TFDQuery but is not working with TMSQuery.

Thank you!

Stellar
Devart Team
Posts: 248
Joined: Tue 03 Oct 2017 11:00

Re: Error with Parameters named "like" variables

Post by Stellar » Mon 26 Nov 2018 15:14

SDAC replaces Delphi parameters with SQL parameters with the same name in SQL statements. In this case, the :CLIENTE_ID is replaced with the SQL parameter @CLIENTE_ID. Since the @CLIENTE_ID parameter already exists in the SQL statement, the exception "The variable name '@CLIENTE_ID,' has already been declared" occurs. To solve the issue, you can change the parameter name, for example:

Code: Select all

DECLARE @CLIENTE_ID INT
SET @CLIENTE_ID = :CLIENTEID
SELECT 'CLIENTE :'+CAST(@CLIENTE_ID AS VARCHAR)

Post Reply