Solved

sql statement issues

Posted on 2014-04-01
3
236 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
[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
  • 2
3 Comments
 
LVL 143

Expert Comment

by:Guy Hengel [angelIII / a3]
ID: 39969510
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 143

Accepted Solution

by:
Guy Hengel [angelIII / a3] earned 500 total points
ID: 39969518
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
ID: 39969544
thank you. I need to think of the NOT as a logic gate in electronics..
0

Featured Post

How Do You Stack Up Against Your Peers?

With today’s modern enterprise so dependent on digital infrastructures, the impact of major incidents has increased dramatically. Grab the report now to gain insight into how your organization ranks against your peers and learn best-in-class strategies to resolve incidents.

Question has a verified solution.

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

Suggested Solutions

If you find yourself in this situation “I have used SELECT DISTINCT but I’m getting duplicates” then I'm sorry to say you are using the wrong SQL technique as it only does one thing which is: produces whole rows that are unique. If the results you a…
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/…
I've attached the XLSM Excel spreadsheet I used in the video and also text files containing the macros used below. https://filedb.experts-exchange.com/incoming/2017/03_w12/1151775/Permutations.txt https://filedb.experts-exchange.com/incoming/201…
Finding and deleting duplicate (picture) files can be a time consuming task. My wife and I, our three kids and their families all share one dilemma: Managing our pictures. Between desktops, laptops, phones, tablets, and cameras; over the last decade…

730 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