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

Re: Help with variable SQL queries by Ray

Ray
Thu Aug 28 09:13:17 CDT 2003

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
>
>



Re: Help with variable SQL queries by Dave

Dave
Thu Aug 28 10:00:59 CDT 2003

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
> >
> >
>
>



Re: Help with variable SQL queries by Ray

Ray
Thu Aug 28 10:22:07 CDT 2003

Oops. I forgot 1,3

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
> > >
> > >
> >
> >
>
>



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
> > > >
> > > >
> > >
> > >
> >
> >
>
>



Re: Help with variable SQL queries by Dave

Dave
Thu Aug 28 10:36:54 CDT 2003

BTW, if only they were still making them like Audry Hepburn...


"Ray at <%=sLocation%>" <myfirstname at lane34 dot com> wrote in message
news:u6KlmgXbDHA.4020@tk2msftngp13.phx.gbl...
> Oops. I forgot 1,3
>
> 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
> > > >
> > > >
> > >
> > >
> >
> >
>
>



Re: Help with variable SQL queries by Ray

Ray
Thu Aug 28 10:38:57 CDT 2003

Yeah, for real. Elegance at its best! :]

Ray at work

"Dave" <dave35426@yahoo.com> wrote in message
news:O1fn2oXbDHA.3360@tk2msftngp13.phx.gbl...
> BTW, if only they were still making them like Audry Hepburn...
>
>
> "Ray at <%=sLocation%>" <myfirstname at lane34 dot com> wrote in message



Re: Help with variable SQL queries by Dave

Dave
Thu Aug 28 11:35:49 CDT 2003

That works great, except I get a variable type mismatch error if more than
one checkbox is checked. Here is the expr:

CCrit=Request.Form("CL")

If Request.Form("CL") Then Criteria="ClassroomID IN (" &CCrit& ")"

Ive also tried

If Request.Form("CL") then Criteria="ClassroomID IN (" + CCrit +")"

Any thoughts?

oh, here's the error:

Microsoft VBScript runtime (0x800A000D)
Type mismatch: '[string: "1, 2"]'


Thanks,
Dave

"Ray at <%=sLocation%>" <myfirstname at lane34 dot com> wrote in message
news:u6KlmgXbDHA.4020@tk2msftngp13.phx.gbl...
> Oops. I forgot 1,3
>
> 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
> > > >
> > > >
> > >
> > >
> >
> >
>
>



<