Article View: borland.public.cppbuilder.database.ado
Article #3850Re: Dynamic SQL - How do I create dynamic SQL statements on the fly?
From: Steve Kothenbeutel
Date: Thu, 06 Jun 2002 22:27
Date: Thu, 06 Jun 2002 22:27
58 lines
3089 bytes
3089 bytes
Here is my clarification.
Consider the following SQL statement:
select * from table1 where name='steven' and age=25
lets say that the user sends back just the name parameter and does not wish
to search using the age parameter... how do I customize the SQL statement to
reflect this?
Essentially I would like to dynamically take one SQL statement and be able
to change it according to the specified parameters sent from a user. So, I
would like to search using any number of parameters with "and" or "or"
operators in the SQL statement. How do I set these without having to
hardcode it into the SQL statement within the program?
Thanks!
Steve Kothenbeutel
skothenbeutel@consultant.com
"Steve Kothenbeutel" <skothenbeutel@consultant.com> wrote in message
news:3cffb4e2_2@dnews...
> What happens when I have any number of arguments to pass? This is my
> problem. For example... if the user sends 2 arguments back, I want to be
> able to change the SQL... and if the user sends just one argument, then I
> want to be able to change the SQL... see my point?
>
> Thanks for the assitance!
>
> "Clay Shannon" <cshannon@amfam.com> wrote in message
> news:3cff9614$1_1@dnews...
> > Use the Format function, zB:
> >
> > Format('Select %s, %s FROM %s where %s = %s',
> > [arg1, arg2, arg3, arg4]);
> >
> > "Steve Kothenbeutel" <skothenbeutel@consultant.com> wrote in message
> > news:3cff342f_2@dnews...
> > > Hello,
> > >
> > > I am trying to create dynamic SQL statements that depend on user
input.
> I
> > > am aware of the Parameters property in TADOQuery for example... but I
am
> > > unsure how to use it in the following scenario:
> > >
> > > A user sends a request for information as such:
> > >
> > > select :readfields from table1 where :conditions
> > >
> >
> >
>
>
Technical Details
Message-ID:
<3cffe0fb_2@dnews>Path:
arc1-ca.pugleaf.net!archiver1.google.com!news1.google.com!sn-xit-02!sn-xit-03!supernews.com!newsswitch.lcs.mit.edu!news-spur1.maxwell.syr.edu!news.maxwell.syr.edu!fr.clara.net!heighliner.fr.clara.net!newsfeed01.sul.t-online.de!t-online.de!dnewsReferences:
<3cff342f_2@dnews> <3cff9614$1_1@dnews> <3cffb4e2_2@dnews>Show Full Headers
Complete Article Headers
X-Google-Language: ENGLISH,ASCII-7-bit X-Google-Thread: fcd2b,a8d67f18caa8caff X-Google-Attributes: gidfcd2b,public X-Google-Thread: 10698b,a8d67f18caa8caff X-Google-Attributes: gid10698b,public X-Google-Thread: f6386,a8d67f18caa8caff X-Google-Attributes: gidf6386,public X-Google-ArrivalTime: 2002-06-06 15:39:54 PST From: "Steve Kothenbeutel" <skothenbeutel@consultant.com> Newsgroups: borland.public.cppbuilder.database.ado,borland.public.cppbuilder.database.multi-tier,borland.public.delphi.database.multi-tier References: <3cff342f_2@dnews> <3cff9614$1_1@dnews> <3cffb4e2_2@dnews> Subject: Re: Dynamic SQL - How do I create dynamic SQL statements on the fly? Date: Thu, 6 Jun 2002 15:27:04 -0700 Lines: 60 X-Priority: 3 X-MSMail-Priority: Normal X-Newsreader: Microsoft Outlook Express 5.00.2919.6700 X-MimeOLE: Produced By Microsoft MimeOLE V5.00.2919.6700 NNTP-Posting-Host: 172.193.171.2 Message-ID: <3cffe0fb_2@dnews> X-Trace: dnews 1023402235 172.193.171.2 (6 Jun 2002 15:23:55 -0700) Path: arc1-ca.pugleaf.net!archiver1.google.com!news1.google.com!sn-xit-02!sn-xit-03!supernews.com!newsswitch.lcs.mit.edu!news-spur1.maxwell.syr.edu!news.maxwell.syr.edu!fr.clara.net!heighliner.fr.clara.net!newsfeed01.sul.t-online.de!t-online.de!dnews