Re: Help with variable SQL queries by Dave
Dave
Thu Aug 28 10:29:33 CDT 2003
I didn't know that about checkboxes. Thanks a lot. I'll try it out now!
Dave
"Ray at <%=sLocation%>" <myfirstname at lane34 dot com> wrote in message
news:eNQYZgXbDHA.2296@TK2MSFTNGP09.phx.gbl...
> Yes, but instead of all the ORs, you can use IN and not worry about it.
> Your possible queries would then be
>
> SELECT * FROM Table1 WHERE ClassID IN (1)
> SELECT * FROM Table1 WHERE ClassID IN (2)
> SELECT * FROM Table1 WHERE ClassID IN (3)
> SELECT * FROM Table1 WHERE ClassID IN (1,2)
> SELECT * FROM Table1 WHERE ClassID IN (2,3)
> SELECT * FROM Table1 WHERE ClassID IN (1,2,3)
>
> The checkboxes with all the same name will take care of making the
> possibilities for you.
>
> Ray at work
>
>
> "Dave" <dave35426@yahoo.com> wrote in message
> news:eUDayUXbDHA.2620@TK2MSFTNGP09.phx.gbl...
> > Yeah, that makes sense, but all three are possible search criteria. So I
> > want the conditinal to pick one of the following SQL statements:
> >
> > SELECT * FROM Table1 WHERE ClassID=1
> > or
> > SELECT * FROM Table1 WHERE ClassID=2
> > or
> > SELECT * FROM Table1 WHERE ClassID=3
> > or
> > SELECT * FROM Table1 WHERE ClassID=(1 OR 2)
> > or
> > SELECT * FROM Table1 WHERE ClassID=(1 OR 3)
> > or
> > SELECT * FROM Table1 WHERE ClassID=(2 OR 3)
> > or
> > SELECT * FROM Table1 WHERE ClassID=(1 OR 2 OR 3)
> >
> > Does that make sense?
> >
> > thanks,
> >
> > Dave
> >
> >
> > "Ray at <%=sLocation%>" <myfirstname at lane34 dot com> wrote in message
> > news:OHpKI6WbDHA.2136@TK2MSFTNGP10.phx.gbl...
> > > Here is how Audrey Hepburn would have done it.
> > >
> > > Your form would have values like:
> > > <input name="CL" value="1" type="checkbox">
> > > <input name="CL" value="2" type="checkbox">
> > > <input name="CL" value="3" type="checkbox">
> > >
> > > Then the page that processes it would be:
> > >
> > > ClasCrit = Request.Form("CL")
> > >
> > > If Len(ClasCrit) < 1 Then
> > > Response.Write "Select at least one option."
> > > Response.End
> > > Else
> > > sSQL = "SELECT WHATEVER FROM WHERE WHERE SOMETHING IN (" &
ClasCrit
> &
> > > ")"
> > > '''rest of your code
> > > End If
> > >
> > >
> > > Does this make sense?
> > >
> > > Ray at work
> > >
> > >
> > >
> > > "Dave" <dave35426@yahoo.com> wrote in message
> > > news:%23FbowsWbDHA.1940@TK2MSFTNGP10.phx.gbl...
> > > > Hi All,
> > > >
> > > > I'm writing a asp page to create queries to a database and want my
> users
> > > to
> > > > be able to specify criteria. So far, I've come up with the following
> > code:
> > > >
> > > > If Request.Form("CL1") AND NOT Request.Form("CL2") AND NOT
> > > > Request.Form("CL3") then ClasCrit="1"
> > > > If Request.Form("CL2") AND NOT Request.Form("CL1") AND NOT
> > > > Request.Form("CL3") Then ClasCrit="2"
> > > > If Request.Form("CL3") AND NOT Request.Form("CL1") AND NOT
> > > > Request.Form("CL2") Then ClasCrit="3"
> > > > If Request.Form("CL1") AND Request.Form("CL2") then ClasCrit="1 OR
2"
> > > > If Request.Form("CL1") AND Request.Form("CL3") then ClasCrit="1 OR
3"
> > > > If Request.Form("CL2") AND Request.Form("CL3") AND NOT
> > Request.Form("CL1")
> > > > then ClasCrit="2 OR 3"
> > > > If Request.Form("CL1") AND Request.Form("CL2") AND
Request.Form("CL3")
> > > then
> > > > ClasCrit="1 OR 2 OR 3"
> > > >
> > > > It works, but is there a more elegant and succinct way of doing the
> same
> > > > thing? My way seems very cubersome.
> > > >
> > > > Thanks for any input,
> > > >
> > > > Dave
> > > >
> > > >
> > >
> > >
> >
> >
>
>