Solved

Select Statment

Posted on 2011-03-08
7
266 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
  • 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 125 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
Backup Your Microsoft Windows Server®

Backup all your Microsoft Windows Server – on-premises, in remote locations, in private and hybrid clouds. Your entire Windows Server will be backed up in one easy step with patented, block-level disk imaging. We achieve RTOs (recovery time objectives) as low as 15 seconds.

 
LVL 74

Assisted Solution

by:käµfm³d 👽
käµfm³d   👽 earned 125 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 119

Assisted Solution

by:Rey Obrero
Rey Obrero earned 250 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 119

Assisted Solution

by:Rey Obrero
Rey Obrero earned 250 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

Better Security Awareness With Threat Intelligence

See how one of the leading financial services organizations uses Recorded Future as part of a holistic threat intelligence program to promote security awareness and proactively and efficiently identify threats.

Join & Write a Comment

Entity Framework is a powerful tool to help you interact with the DataBase but still doesn't help much when we have a Stored Procedure that returns more than one resultset. The solution takes some of out-of-the-box thinking; read on!
I annotated my article on ransomware somewhat extensively, but I keep adding new references and wanted to put a link to the reference library.  Despite all the reference tools I have on hand, it was not easy to find a way to do this easily. I finall…
In Microsoft Access, learn how to “cascade” or have the displayed data of one combo control depend upon what’s entered in another. Base the dependent combo on a query for its row source: Add a reference to the first combo on the form as criteria i…
Polish reports in Access so they look terrific. Take yourself to another level. Equations, Back Color, Alternate Back Color. Write easy VBA Code. Tighten space to use less pages. Launch report from a menu, considering criteria only when it is filled…

706 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

23 Experts available now in Live!

Get 1:1 Help Now