Page 1 of 1

Error with Parameters named "like" variables

Posted: Fri 23 Nov 2018 17:46
by mguzman69
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!

Re: Error with Parameters named "like" variables

Posted: Mon 26 Nov 2018 15:14
by Stellar
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)