Solved

Problem with WHERE Clause

Posted on 2010-11-15
8
526 Views
Last Modified: 2013-11-11
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
Comment
Question by:baxtalo
  • 3
  • 2
  • 2
  • +1
8 Comments
 
LVL 13

Accepted Solution

by:
samic400 earned 250 total points
ID: 34139234
WHERE REPORT_MONTH LIKE '%" & Request.Form("MyReport_Month") & "%' AND REPORT_YEAR LIKE '%" & Request.Form("MyReport_Year") & "%'
0
 
LVL 13

Assisted Solution

by:Rick
Rick earned 250 total points
ID: 34139238
"WHERE REPORT_MONTH = '" & Request.Form("MyReport_Month") & "' AND REPORT_YEAR = '" & Request.Form("MyReport_Year") & "'
0
 
LVL 13

Expert Comment

by:samic400
ID: 34139257
So it should be something like this -

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


0
DevOps Toolchain Recommendations

Read this Gartner Research Note and discover how your IT organization can automate and optimize DevOps processes using a toolchain architecture.

 
LVL 95

Expert Comment

by:Lee W, MVP
ID: 34139326
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
 

Author Closing Comment

by:baxtalo
ID: 34139327
Thank you, it's working now.
0
 

Author Comment

by:baxtalo
ID: 34139349
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
 

Author Comment

by:baxtalo
ID: 34139372
Thank you everyone, I learnt a lot.
Leew, thank you for the detailed explanation.
0
 
LVL 95

Expert Comment

by:Lee W, MVP
ID: 34139387
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

DevOps Toolchain Recommendations

Read this Gartner Research Note and discover how your IT organization can automate and optimize DevOps processes using a toolchain architecture.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

This demonstration started out as a follow up to some recently posted questions on the subject of logging in: http://www.experts-exchange.com/Programming/Languages/Scripting/JavaScript/Q_28634665.html and http://www.experts-exchange.com/Programming/…
Note: You must have administrative privileges in order to create/edit Sharing Rules. Salesforce.com (http://www.salesforce.com) (SFDC) is a cloud-based customer relationship management (CRM) system. It is a database most commonly used by sales an…
Email security requires an ever evolving service that stays up to date with counter-evolving threats. The Email Laundry perform Research and Development to ensure their email security service evolves faster than cyber criminals. We apply our Threat…
Finds all prime numbers in a range requested and places them in a public primes() array. I've demostrated a template size of 30 (2 * 3 * 5) but larger templates can be built such 210  (2 * 3 * 5 * 7) or 2310  (2 * 3 * 5 * 7 * 11). The larger templa…

773 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question