🚀 go-pugleaf

RetroBBS NetNews Server

Inspired by RockSolid Light RIP Retro Guy

Article View: borland.public.cppbuilder.database.ado
Article #1607

Re: Flexible SQL Queries through ADO.

#1607
From: Heinz Ketchup
Date: Mon, 31 May 2004 15:19
59 lines
2721 bytes
Thanks Mark,

The first method works fine for me.

Although I did try your second method, and it didn't seem to work. 
Is there something special that changes in the SQL Query?

i.e.
C++ Code
DynamicFlexSQLStmt = "SELECT :Var1, :Var2 ";
DynamicFlexSQLStmt += "FROM mySQLTable ";
DynamicFlexSQLStmt += "WHERE Date >= :StartDate ";
DynamicFlexSQLStmt += "AND Date <= :EndDate ";

TADOQuery1->Parameters->ParseSQL(DynamicFlexSQLStmt, true);
TADOQuery1->Parameters->ParamByName("Var1")->Value = "Date";
etc...

Debugging the DynamicFlexSQLStmt 
DynamicFlexSQLStmt = "SELECT ?, ? FROM mySQLTable WHERE Date >= ? AND Date <= ?"
It starts when the ParseSQL statement command is executed,
and remains that way after all the ParamByName statements are called

I get an error "No Value given for one or more required Parameters"

Any thoughts?
And THANKS A LOT for the your reply!
You've helped a whole heaps load!

Heinz.



"Mark Guerrieri" <markg11@comcast.net> wrote:
>>
>> AnsiString DynamicFlexSQLStmt = "SELECT Date " + ""... (Whatever I add for
>Column Selections)
>>
>> I cannont use TADOQuery1->SQL->Add(":MyFlexibleSQLStmt");
>> TADOQuery1->SQL->Parameters->ParamByName("MyFlexibleSQLStmt")->Value =
>DynamicFlexSQLStmt;
>>
>
>Try this-
>
>AnsiString DynamicFlexSQLStmt = "SELECT Date " + ""... (Whatever I add for
>Column Selections)
>TADOQuery1->SQL->Text = DynamicFlexSQLStmt;
>
>I do this all the time and it works fine.  I don't bother with parameters,
>I just build the values right into the SQL statement.  If you need
>parameters, add this:
>
>TADOQuery1->Parameters->ParseSQL(DynamicFlexSQLStmt, true);
>TADOQuery1->Parameters->ParamByName("ParamName")->Value = ParamValue;
>
>Mark
>
>
Technical Details
Message-ID: <40bb4d03$1@newsgroups.borland.com>
Path: arc1-ca.pugleaf.net!controlnews3.google.com!news2.google.com!fu-berlin.de!newsfeed.iinet.net.au!newsfeed.iinet.net.au!PeerFeed.KWeb.on.ca!news.kweb.on.ca!newsgroups.borland.com!not-for-mail
References: <40ba50b3$1@newsgroups.borland.com> <40baa32b$1@newsgroups.borland.com>

Show Full Headers
Complete Article Headers
X-Google-Language: ENGLISH,ASCII-7-bit
X-Google-Thread: 10698b,88aab88ffc95b09
X-Google-Attributes: gid10698b,public
From: "Heinz Ketchup" <heinz_like_the_ketchup@h0tmail.no_spam.c0m.no_spam>
Sender: "Heinz Ketchup" <heinz_like_the_ketchup@h0tmail.no_spam.c0m.no_spam>
Reply-To: "Heinz Ketchup" <heinz_like_the_ketchup@h0tmail.no_spam.c0m.no_spam>
Subject: Re: Flexible SQL Queries through ADO.
Newsgroups: borland.public.cppbuilder.database.ado
X-User-Info: 146.131.120.2     
References: <40ba50b3$1@newsgroups.borland.com> <40baa32b$1@newsgroups.borland.com>
NNTP-Posting-Host: 207.105.83.66
Message-ID: <40bb4d03$1@newsgroups.borland.com>
Date: 31 May 2004 08:19:31 -0700
X-Trace: newsgroups.borland.com 1086016771 207.105.83.66 (31 May 2004 08:19:31 -0700)
Lines: 61
Path: arc1-ca.pugleaf.net!controlnews3.google.com!news2.google.com!fu-berlin.de!newsfeed.iinet.net.au!newsfeed.iinet.net.au!PeerFeed.KWeb.on.ca!news.kweb.on.ca!newsgroups.borland.com!not-for-mail