Solved

Select Statment

Posted on 2011-03-08
7
271 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 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
Comprehensive Backup Solutions for Microsoft

Acronis protects the complete Microsoft technology stack: Windows Server, Windows PC, laptop and Surface data; Microsoft business applications; Microsoft Hyper-V; Azure VMs; Microsoft Windows Server 2016; Microsoft Exchange 2016 and SQL Server 2016.

 
LVL 75

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 120

Assisted Solution

by:Rey Obrero (Capricorn1)
Rey Obrero (Capricorn1) 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 120

Assisted Solution

by:Rey Obrero (Capricorn1)
Rey Obrero (Capricorn1) 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

Free Tool: Postgres Monitoring System

A PHP and Perl based system to collect and display usage statistics from PostgreSQL databases.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

This article describes two methods for creating a combo box that can be used to add new items to the row source -- one for simple lookup tables, and one for a more complex row source where the new item needs data for several fields.
You need to know the location of the Office templates folder, so that when you create new templates, they are saved to that location, and thus are available for selection when creating new documents.  The steps to find the Templates folder path are …
Basics of query design. Shows you how to construct a simple query by adding tables, perform joins, defining output columns, perform sorting, and apply criteria.
What’s inside an Access Desktop Database. Will look at the basic interface, Navigation Pane (Database Container), Tables, Queries, Forms, Report, Macro’s, and VBA code.

733 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