SQL Help

  • Thread starter Thread starter Matt
  • Start date Start date
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
 
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
 
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
 
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
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Similar Threads

SQL help 1
Excel Export Filtered Form Data To Excel 0
Reference Formula Help 1
sql help 1
EXCEL problem- mortgage 0
VBA SQL statement help 5
Access MS Access Training Database 0
SQL Statement help 3

Back
Top