Article View: borland.public.cppbuilder.database.ado
Article #3852Re: Dynamic SQL - How do I create dynamic SQL statements on the fly?
From: Claude Bissonnette
Date: Fri, 07 Jun 2002 01:10
Date: Fri, 07 Jun 2002 01:10
74 lines
3578 bytes
3578 bytes
Create your sql string is the best way to solve your problem. Dave
Rowntree is right. You can then split your SQL in multiple functions, 1 for
eatch part of your sql ... like the Select, join, where, order by ...
Claude Bissonnette
"Steve Kothenbeutel" <skothenbeutel@consultant.com> wrote in message
news:3cffe0fb_2@dnews...
> 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:
<3d00081e_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!newsfeed.icl.net!newspeer.clara.net!news.clara.net!newsfeed01.sul.t-online.de!t-online.de!dnewsReferences:
<3cff342f_2@dnews> <3cff9614$1_1@dnews> <3cffb4e2_2@dnews> <3cffe0fb_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: f6386,a8d67f18caa8caff X-Google-Attributes: gidf6386,public X-Google-Thread: 10698b,a8d67f18caa8caff X-Google-Attributes: gid10698b,public X-Google-ArrivalTime: 2002-06-06 18:13:16 PST From: "Claude Bissonnette" <cbisson@forgestik.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> <3cffe0fb_2@dnews> Subject: Re: Dynamic SQL - How do I create dynamic SQL statements on the fly? Date: Thu, 6 Jun 2002 21:10:27 -0400 Lines: 76 X-Priority: 3 X-MSMail-Priority: Normal X-Newsreader: Microsoft Outlook Express 5.50.4807.1700 X-MimeOLE: Produced By Microsoft MimeOLE V5.50.4910.0300 NNTP-Posting-Host: 65.92.137.88 Message-ID: <3d00081e_2@dnews> X-Trace: dnews 1023412254 65.92.137.88 (6 Jun 2002 18:10:54 -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!newsfeed.icl.net!newspeer.clara.net!news.clara.net!newsfeed01.sul.t-online.de!t-online.de!dnews