Go Premium for a chance to win a PS4. Enter to Win

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 543
  • Last Modified:

Problem with WHERE Clause

My where clause doesn't return the values from the database. This is how I'm trying to call the values:
WHERE REPORT_MONTH = '%" & Request.Form("MyReport_Month") & "%' AND REPORT_YEAR = '%" & Request.Form("MyReport_Year") & "%'
What am I doning wrong?
Thanks for your help
0
baxtalo
Asked:
baxtalo
  • 3
  • 2
  • 2
  • +1
2 Solutions
 
samic400Commented:
WHERE REPORT_MONTH LIKE '%" & Request.Form("MyReport_Month") & "%' AND REPORT_YEAR LIKE '%" & Request.Form("MyReport_Year") & "%'
0
 
RickCommented:
"WHERE REPORT_MONTH = '" & Request.Form("MyReport_Month") & "' AND REPORT_YEAR = '" & Request.Form("MyReport_Year") & "'
0
 
samic400Commented:
So it should be something like this -

SELECT * FROM suppliers WHERE supplier_name like '%IBM%';


0
Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 
Lee W, MVPTechnology and Business Process AdvisorCommented:
To clarify so that perhaps in the future you don't have this problem, you only use % when using LIKE, not =.

Assume for the moment "MyReport_Month" = 11

Your code ends up saying:
WHERE REPORT_MONTH = '%11%'
If the field is not exactly, character for character '%11%' it won't find anything.

If you used LIKE instead of =, then you would get hits (but it would potentially return incorrect data - for example, if someone said the month was 1 as in January, then your query using LIKE would return data for January, October, November, and December since all those months have a 1 in them (unless you forced the search to look for 01).

So the correct solution should be rick_gwu's which removes the % signs.

However, if you're using a field where the data is ALWAYS a month number, then that field would likely be better as a numeric field and wouldn't require ' characters to denote text and you wouldn't use "%" signs at all - you would use standard math signs.
0
 
baxtaloAuthor Commented:
Thank you, it's working now.
0
 
baxtaloAuthor Commented:
I'm sorry leew, I awarded the points before I read your reply. This is how I called the value:
" & Request.Form("MyReport_Year") & "
0
 
baxtaloAuthor Commented:
Thank you everyone, I learnt a lot.
Leew, thank you for the detailed explanation.
0
 
Lee W, MVPTechnology and Business Process AdvisorCommented:
No problem, just try to understand what you did/what I said so this isn't an issue for you in the future.  I thought the previous posters did a poor job (well, didn't at all) explain what they did to correct your problem in which case, how could you learn?
0

Featured Post

Free Tool: Site Down Detector

Helpful to verify reports of your own downtime, or to double check a downed website you are trying to access.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

  • 3
  • 2
  • 2
  • +1
Tackle projects and never again get stuck behind a technical roadblock.
Join Now