BorlandTalk.com Forum Index BorlandTalk.com
Borland discussion newsgroups
 
Archives   FAQFAQ   SearchSearch   MemberlistMemberlist   UsergroupsUsergroups   RegisterRegister 
 ProfileProfile   Log in to check your private messagesLog in to check your private messages   Log inLog in 

Parameters with same name in one query

 
Post new topic   Reply to topic    BorlandTalk.com Forum Index -> Delphi Databases (ADO)
View previous topic :: View next topic  
Author Message
Sascha Schroeder
Guest





PostPosted: Mon Feb 23, 2004 1:18 pm    Post subject: Parameters with same name in one query Reply with 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
Kevin Frevert
Guest





PostPosted: Mon Feb 23, 2004 1:24 pm    Post subject: Re: Parameters with same name in one query Reply with quote



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





PostPosted: Mon Feb 23, 2004 1:51 pm    Post subject: Re: Parameters with same name in one query Reply with quote



"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





PostPosted: Mon Feb 23, 2004 4:33 pm    Post subject: Re: Parameters with same name in one query Reply with quote

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
Display posts from previous:   
Post new topic   Reply to topic    BorlandTalk.com Forum Index -> Delphi Databases (ADO) All times are GMT
Page 1 of 1

 
Jump to:  
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


Powered by phpBB © 2001, 2006 phpBB Group
SEO toolkit © 2004-2006 webmedic.