Solved

sql statement issues

Posted on 2014-04-01
3
230 Views
Last Modified: 2014-04-01
I am pulling data to a web page from a named range in excel. the named range is called tblData. On my page I have two tables. the first table is populated via the following sql statement:
***************
sql = "SELECT * FROM tblData where (TagName LIKE '%Throttle_PctMax%' OR TagName LIKE '%Section1_IsenEff%' OR TagName LIKE '%Section2_IsenEff%' OR TagName LIKE '%Section3_IsenEff%' OR TagName LIKE '%Section4_IsenEff%' OR TagName LIKE '%WtPctLiqInExh%' OR TagName LIKE '%TotalLostMWs%') AND Asset LIKE '%ST201-WCO%';"
****************
and it works exactly like I want it to. the second table i want to exclude all the stuff from the table 1 so i used the following sql statement:
****************
sql = "SELECT * FROM tblData where (TagName NOT LIKE '%Throttle_PctMax%' OR TagName NOT LIKE '%Section1_IsenEff%' OR TagName NOT LIKE '%Section2_IsenEff%' OR TagName NOT LIKE '%Section3_IsenEff%' OR TagName NOT LIKE '%Section4_IsenEff%' OR TagName NOT LIKE '%WtPctLiqInExh%' OR TagName NOT LIKE '%TotalLostMWs%') AND Asset LIKE 'ST201-WCO%';"
*****************
and that returns everything including the stuff from table 1.

what am i doing wrong?
0
Comment
Question by:jlcannon
  • 2
3 Comments
 
LVL 142

Expert Comment

by:Guy Hengel [angelIII / a3]
Comment Utility
NOT x OR NOT y is not what you want to do, but a NOT (x OR y)
this is "purely logic", see how this would look like in the code:
sql = "SELECT * FROM tblData 
where NOT (TagName LIKE '%Throttle_PctMax%' OR TagName LIKE '%Section1_IsenEff%' OR TagName LIKE '%Section2_IsenEff%' OR TagName LIKE '%Section3_IsenEff%' OR TagName LIKE '%Section4_IsenEff%' OR TagName LIKE '%WtPctLiqInExh%' OR TagName NOT '%TotalLostMWs%') 
AND Asset LIKE 'ST201-WCO%';"

Open in new window

0
 
LVL 142

Accepted Solution

by:
Guy Hengel [angelIII / a3] earned 500 total points
Comment Utility
NOT x OR NOT y  is not what you want to do, but
NOT ( x OR y )
or
NOT X AND NOT y

this is "purely logic", in code it would look like this:
sql = "SELECT * FROM tblData where NOT (TagName LIKE '%Throttle_PctMax%' OR TagName LIKE '%Section1_IsenEff%' OR TagName LIKE '%Section2_IsenEff%' OR TagName LIKE '%Section3_IsenEff%' OR TagName LIKE '%Section4_IsenEff%' OR TagName  LIKE '%WtPctLiqInExh%' OR TagName LIKE '%TotalLostMWs%') AND Asset LIKE 'ST201-WCO%';"

Open in new window

0
 

Author Closing Comment

by:jlcannon
Comment Utility
thank you. I need to think of the NOT as a logic gate in electronics..
0

Featured Post

How to improve team productivity

Quip adds documents, spreadsheets, and tasklists to your Slack experience
- Elevate ideas to Quip docs
- Share Quip docs in Slack
- Get notified of changes to your docs
- Available on iOS/Android/Desktop/Web
- Online/Offline

Join & Write a Comment

Have you ever needed to get an ASP script to wait for a while? I have, just to let something else happen. Or in my case, to allow other stuff to happen while I was murdering my MySQL database with an update. The Original Issue This was written…
Composite queries are used to retrieve the results from joining multiple queries after applying any filters. UNION, INTERSECT, MINUS, and UNION ALL are some of the operators used to get certain desired results.​
Here's a very brief overview of the methods PRTG Network Monitor (https://www.paessler.com/prtg) offers for monitoring bandwidth, to help you decide which methods you´d like to investigate in more detail.  The methods are covered in more detail in o…
This video explains how to create simple products associated to Magento configurable product and offers fast way of their generation with Store Manager for Magento tool.

771 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

Need Help in Real-Time?

Connect with top rated Experts

10 Experts available now in Live!

Get 1:1 Help Now