SQL Help

M

Matt

Hi,

I am trying to display records from a db and want to
select using a where like command. Here is what I have so
far...
strSQL="SELECT * FROM Reports WHERE Month LIKE " &
Request.QueryString("Month") & ""
The month var. is a number in the db. Can someone help me
with the correct syntax for this statement? I would like
to be able to search by month 1 to 12 or enter % to select
all months.

Thanks,

Matt
 
A

anonymous

Don't know exactly why you have decided to perform
a "Like" query if the submitted number is the number you
are looking for, but here's something to try:
if Request.QueryString("Month") = "" then
strSQL="SELECT * FROM Reports"
else
strSQL="SELECT * FROM Reports where MONTH='" &
Request.QueryString("Month") &"'"
end if

I do not know what your DB field type is, but use the cstr
or cint on the request.querystring value if you receive
any type mismatch errors
 
J

Jon Spivey

Hi,
your syntax looks fine except don't use like - if you're accepting a month
in the query string either the record matches th
 
J

Jon Spivey

Hi,
your syntax looks fine except don't use like - if you're accepting a month
in the query string either the record matches or it doesnt.

SELECT *
FROM Reports
WHERE [Month] = Request.QueryString("Month")

You might want to make sure the month is valid - ie between 1 and 12 -
before you query. Also watch your field names - things like month are
reserved words. If you must use them surround with square brackets
 
Top