Solved

Problem with WHERE Clause

Posted on 2010-11-15
8
533 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 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
 Watch the Recording: Learning MySQL 5.7

MySQL 5.7 has a lot of new features. If you've dabbled with an older version of MySQL, it is definitely worth learning.

 
LVL 96

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 96

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

Online Training Solution

Drastically shorten your training time with WalkMe's advanced online training solution that Guides your trainees to action. Forget about retraining and skyrocket knowledge retention rates.

Question has a verified solution.

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

Oracle Apps Profiles option: A user profile is a set of shifting options that alter the way one runs an application. A value is set for each option under the user's profile when the Oracle application user logs on to any responsibility or changes…
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/…
If you’ve ever visited a web page and noticed a cool font that you really liked the look of, but couldn’t figure out which font it was so that you could use it for your own work, then this video is for you! In this Micro Tutorial, you'll learn yo…
Visualize your data even better in Access queries. Given a date and a value, this lesson shows how to compare that value with the previous value, calculate the difference, and display a circle if the value is the same, an up triangle if it increased…

626 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