Solved

SQL query on ASP page not working

Posted on 2014-03-27
10
231 Views
Last Modified: 2014-03-27
I am pulling data to an ASP page from excel data in a named range. the named range is called "tblData" and I want the data from all the assets that are named a certain thing. My current sql statement is below and it retuns all assets but it does only pull the tagnames I am looking for but just not the specific assets, it pull all assets. the piece in italics is whats not working.

sql = "SELECT * FROM tblData where Asset ='FB%DPO' AND TagName = 'PercentMCR' OR 'BoilerCycles' OR 'BoilerThermalEfficiency' OR 'BoilerAvailableWorkEfficiency';"
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
  • 5
  • 3
  • 2
10 Comments
 
LVL 34

Expert Comment

by:ste5an
ID: 39958760
Seems you want:

SELECT * 
FROM tblData 
WHERE Asset ='FB%DPO'  
  AND TagName IN ('PercentMCR', 'BoilerCycles', 'BoilerThermalEfficiency', 'BoilerAvailableWorkEfficiency');

Open in new window

0
 
LVL 29

Assisted Solution

by:Paul Jackson
Paul Jackson earned 250 total points
ID: 39958781
You need to repeat the column you are comparing against in the where clause when using OR :

SELECT * FROM tblData 
where Asset ='FB%DPO'  AND (TagName = 'PercentMCR' OR TagName =  'BoilerCycles' OR TagName = 'BoilerThermalEfficiency' OR TagName = 'BoilerAvailableWorkEfficiency');

Open in new window

0
 

Author Comment

by:jlcannon
ID: 39958787
when i use that it returns nothing. my asset names are like FB3-DPO or FB34DPO so I thought using the wildcard % would get all of what I needed for asset name.  but the above solution does not pull any data and it should as FB%DPO should return the records to the two assets I listed above.
0
Is Your DevOps Pipeline Leaking?

Is your CI/CD pipeline a hodge-podge of randomly connected tools? You’ve likely got a tool to fix one problem & then a different tool to fix another, resulting in a cluster of tools with overlapping functionality. Learn how to optimize your pipeline with Gartner's recommendations

 
LVL 29

Expert Comment

by:Paul Jackson
ID: 39958792
try using the like operator :

SELECT * FROM tblData 
where Asset Like 'FB%DPO'  AND (TagName = 'PercentMCR' OR TagName =  'BoilerCycles' OR TagName = 'BoilerThermalEfficiency' OR TagName = 'BoilerAvailableWorkEfficiency'); 

Open in new window

0
 

Author Comment

by:jlcannon
ID: 39958975
Hmm still returns nothing I have attached a copy of my excel sheet.  and my code is simple, using the lates solution:

sql = "SELECT * FROM tblData where Asset Like 'FB%DPO'  AND (TagName = 'PercentMCR' OR TagName =  'BoilerCycles' OR TagName = 'BoilerThermalEfficiency' OR TagName = 'BoilerAvailableWorkEfficiency');"

set RS = server.createobject("adodb.recordset")
RS.open sql,Conn,adOpenForwardOnly,adLockReadOnly
Copy.xlsx
0
 
LVL 34

Expert Comment

by:ste5an
ID: 39959041
The wildcard is the asterisk *.
0
 

Author Comment

by:jlcannon
ID: 39959059
I have used both * and % and neither return the data
0
 

Author Comment

by:jlcannon
ID: 39959095
It seems as if If I use Asset LIKE 'FB%' is works to pull up all records with Asset names that begin with FB but if I use '%DPO' it pulls nothing. Same if I use 'FB*' it pulls all FB but if I use '*DPO' it pulls nothing. Also if I add in the line from AND on to the end it again pulls nothing even when used in conjunction with FB% than by itself returns all records where the asset name begins with FB... I am at a loss.
0
 
LVL 34

Accepted Solution

by:
ste5an earned 250 total points
ID: 39959136
Yup, it's Excel. You cannot rely on what you see.

The value is 'FB4-DPO    ' with trailing spaces. Thus you need to go for [Asset] LIKE 'FB%DPO%'.
0
 

Author Closing Comment

by:jlcannon
ID: 39959740
thank you. found it was trailing spaces in the cells so now to figure out how to use the equivelent of TRIM in the vba code I am using to import the data from a CSV file. Off to a new searcha nd probably new question here....
0

Featured Post

Guide to Performance: Optimization & Monitoring

Nowadays, monitoring is a mixture of tools, systems, and codes—making it a very complex process. And with this complexity, comes variables for failure. Get DZone’s new Guide to Performance to learn how to proactively find these variables and solve them before a disruption occurs.

Question has a verified solution.

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

'Between' is such a common word we rarely think about it but in SQL it has a very specific definition we should be aware of. While most database vendors will have their own unique phrases to describe it (see references at end) the concept in common …
Confronted with some SQL you don't know can be a daunting task. It can be even more daunting if that SQL carries some of the old secret codes used in the Ye Olde query syntax, such as: (+)     as used in Oracle;     *=     =*    as used in Sybase …
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…

751 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