?
Solved

Select Statment

Posted on 2011-03-08
7
Medium Priority
?
273 Views
Last Modified: 2012-05-11
Im trying to pull my 5 and 6 year olds from a table with this code but it seem to be selecting all the records instead of just the ones from 2011, anyone notice whats wrong?

SQLStmt =  "Select COUNT(*) AS FiveSix"
SQLStmt = SQLStmt & " From ""Reg"" "
SQLStmt = SQLStmt & "Where ""LEAGUEAGE"" = '" & 5 & "' OR  ""LEAGUEAGE"" = '" & 6 & "' AND ""NEWYEAR"" = '" & 2011 & "'"
0
Comment
Question by:darrellbuckley
[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
  • 2
  • 2
  • +1
7 Comments
 

Author Comment

by:darrellbuckley
ID: 35069453
Sorry Wrong Code this is the one..

      SQLStmt = "Select ""ID"", ""PFNAME"", ""PLNAME"", ""BIRTHDATE"", ""SIBNAME"", ""LEAGUEAGE"" , ""LEAGUE"""
      SQLStmt = SQLStmt & " From ""RegForm2009"" "
      SQLStmt = SQLStmt & "Where ""LEAGUEAGE"" = '" & 5 & "' OR  ""LEAGUEAGE"" = '" & 6 & "' AND ""NEWYEAR"" = '" & 2011 & "'"
      SQLStmt = SQLStmt & " ORDER BY ""PFNAME"" ASC; "
0
 
LVL 15

Accepted Solution

by:
derekkromm earned 500 total points
ID: 35069454
SQLStmt =  "Select COUNT(*) AS FiveSix"
SQLStmt = SQLStmt & " From ""Reg"" "
SQLStmt = SQLStmt & "Where (""LEAGUEAGE"" = '" & 5 & "' OR  ""LEAGUEAGE"" = '" & 6 & "') AND ""NEWYEAR"" = '" & 2011 & "'"
0
 
LVL 15

Expert Comment

by:derekkromm
ID: 35069466
Sorry, posted for the original query. Wrap the age=5 or age=6 with parentheses.


SQLStmt = "Select ""ID"", ""PFNAME"", ""PLNAME"", ""BIRTHDATE"", ""SIBNAME"", ""LEAGUEAGE"" , ""LEAGUE"""
      SQLStmt = SQLStmt & " From ""RegForm2009"" "
      SQLStmt = SQLStmt & "Where (""LEAGUEAGE"" = '" & 5 & "' OR  ""LEAGUEAGE"" = '" & 6 & "') AND ""NEWYEAR"" = '" & 2011 & "'"
      SQLStmt = SQLStmt & " ORDER BY ""PFNAME"" ASC; "
0
How Blockchain Is Impacting Every Industry

Blockchain expert Alex Tapscott talks to Acronis VP Frank Jablonski about this revolutionary technology and how it's making inroads into other industries and facets of everyday life.

 
LVL 75

Assisted Solution

by:käµfm³d 👽
käµfm³d   👽 earned 500 total points
ID: 35069507
>>  Im trying to pull my 5 and 6 year olds from a table with this code...

My first thought would be why are you letting your children play on the table...   that's dangerous!

j/k     = )
0
 
LVL 120

Assisted Solution

by:Rey Obrero (Capricorn1)
Rey Obrero (Capricorn1) earned 1000 total points
ID: 35069582
try this one


SQLStmt = "Select ID, PFNAME, PLNAME, BIRTHDATE, SIBNAME, LEAGUEAGE , LEAGUE"
      SQLStmt = SQLStmt & " From RegForm2009"
      SQLStmt = SQLStmt & " Where LEAGUEAGE In('5','6') AND NEWYEAR = '2011'"
      SQLStmt = SQLStmt & " ORDER BY PFNAME ASC;"
0
 

Author Comment

by:darrellbuckley
ID: 35069678
Thanks for the replies but I noticed that I was'nt even pulling the NEWYEAR field, seems to be working now. Thanks
0
 
LVL 120

Assisted Solution

by:Rey Obrero (Capricorn1)
Rey Obrero (Capricorn1) earned 1000 total points
ID: 35069719
well, just add to the select line

SQLStmt = "Select ID, PFNAME, PLNAME, BIRTHDATE, SIBNAME, LEAGUEAGE , LEAGUE,NEWYEAR"
      SQLStmt = SQLStmt & " From RegForm2009"
      SQLStmt = SQLStmt & " Where LEAGUEAGE In('5','6') AND NEWYEAR = '2011'"
      SQLStmt = SQLStmt & " ORDER BY PFNAME ASC;"
0

Featured Post

NFR key for Veeam Backup for Microsoft Office 365

Veeam is happy to provide a free NFR license (for 1 year, up to 10 users). This license allows for the non‑production use of Veeam Backup for Microsoft Office 365 in your home lab without any feature limitations.

Question has a verified solution.

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

Recently I was talking with Tim Sharp, one of my colleagues from our Technical Account Manager team about MongoDB’s scalability. While doing some quick training with some of the Percona team, Tim brought something to my attention...
In this article, we’ll look at how to deploy ProxySQL.
In Microsoft Access, when working with VBA, learn some techniques for writing readable and easily maintained code.
In this video, Percona Solutions Engineer Barrett Chambers discusses some of the basic syntax differences between MySQL and MongoDB. To learn more check out our webinar on MongoDB administration for MySQL DBA: https://www.percona.com/resources/we…
Suggested Courses

770 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