 |
BorlandTalk.com Borland discussion newsgroups
|
| View previous topic :: View next topic |
| Author |
Message |
Sascha Schroeder Guest
|
Posted: Mon Feb 23, 2004 1:18 pm Post subject: Parameters with same name in one query |
|
|
Hello,
i have a query string which contains a sub query, like:
SELECT *
FROM TABLE1
WHERE FIELD1 = :Param1 AND
FIELD2 IN
(SELECT FIELD2
FROM TABLE2
WHERE FIELD3 = :Param1)
I add the query to my query object and replace the parameters:
Query.ParamByName('Param1').AsInteger := 1;
My MSSQL-Server returns no rows but an error. I only get the
message in german, so i don't post it here. The message says, that
a parameter wasn't correct definied.
Is there a trick in ADO to do that? When i use the BDE there is no
problem to do that.
Thanks for your answers,
Sascha
|
|
| Back to top |
|
 |
Kevin Frevert Guest
|
Posted: Mon Feb 23, 2004 1:24 pm Post subject: Re: Parameters with same name in one query |
|
|
Sascha,
That is a "feature" of ADO. Parameter names must be unique.
krf
"Sascha Schroeder" <sascha.schroeder (AT) e-pro (DOT) de> wrote
| Quote: |
Is there a trick in ADO to do that? When i use the BDE there is no
problem to do that.
Thanks for your answers,
Sascha
|
|
|
| Back to top |
|
 |
Mike Walsh Guest
|
Posted: Mon Feb 23, 2004 1:51 pm Post subject: Re: Parameters with same name in one query |
|
|
"Sascha Schroeder" <sascha.schroeder (AT) e-pro (DOT) de> wrote
| Quote: | Is there a trick in ADO to do that? When i use the BDE there is no
problem to do that.
Thanks for your answers,
Sascha
Sasha, |
Like Kevin said, that's how ADO was designed, frankly, imo it's a royal
pain. I use a trick to get around it that seems to work fine, and I've never
had any troubles with it. What I do is I declare a variable in the sql set
it by my parameter, then use the var in the where clause. Your original code
would look like this..
declare
@SomeVar SomeType
set @SomeVar = :Param1
SELECT *
FROM TABLE1
WHERE FIELD1 = @SomeVar AND
FIELD2 IN
(SELECT FIELD2
FROM TABLE2
WHERE FIELD3 = @SomeVar)
Mike Walsh
|
|
| Back to top |
|
 |
Sascha Schroeder Guest
|
Posted: Mon Feb 23, 2004 4:33 pm Post subject: Re: Parameters with same name in one query |
|
|
Thank you very much for your tips,
i will implement a little workaround for this ado 'feature'.
Sascha
"Sascha Schroeder" <sascha.schroeder (AT) e-pro (DOT) de> schrieb im Newsbeitrag
news:4039fdbb (AT) newsgroups (DOT) borland.com...
| Quote: | Hello,
i have a query string which contains a sub query, like:
SELECT *
FROM TABLE1
WHERE FIELD1 = :Param1 AND
FIELD2 IN
(SELECT FIELD2
FROM TABLE2
WHERE FIELD3 = :Param1)
I add the query to my query object and replace the parameters:
Query.ParamByName('Param1').AsInteger := 1;
My MSSQL-Server returns no rows but an error. I only get the
message in german, so i don't post it here. The message says, that
a parameter wasn't correct definied.
Is there a trick in ADO to do that? When i use the BDE there is no
problem to do that.
Thanks for your answers,
Sascha
|
|
|
| Back to top |
|
 |
|
|
You cannot post new topics in this forum You cannot reply to topics in this forum You cannot edit your posts in this forum You cannot delete your posts in this forum You cannot vote in polls in this forum
|
|