[thelist] ASP & SQL
Joshua Olson
joshua at waetech.com
Thu Sep 12 14:15:42 CDT 2002
----- Original Message -----
From: "Jay Blanchard" <jay.blanchard at niicommunications.com>
Sent: Thursday, September 12, 2002 3:06 PM
> Don't forget just Last Name and Location. And actually you would want to
> build queries on single items as well...
>
> First Name Only
> Last Name Only
> Location Only
> First Name & Last Name & Location
> First Name & Last Name
> First name & Location
> Last Name & Location
>
> So you have to be prepared to build 7 queries based on information
supplied.
> You can use a CASE statement to encase them all.
No, bad, grrr...
Just build one query. :-)
But, make it a dynamic query, such as:
strSQL = "SELECT fname, lname, location "
strSQL = strSQL & " FROM employees"
strSQL = strSQL & " WHERE 1 = 1 "
If <varFName> <> "" Then
strSQL = strSQL & " AND fname = '" & <varFName> & "'"
End If
If <varLName> <> "" Then
strSQL = strSQL & " AND lname = '" & <varLName> & "'"
End If
If <varLName> <> "" Then
strSQL = strSQL & " AND location = '" & <varLocation> & "'"
End If
' Now, let's look at what we built
Response.Write strSQL
Obviously, everything wrapped in < and > need to get swapped out with your
variable.
HTH,
-joshua
More information about the thelist
mailing list