Solved

Select Statment

Posted on 2011-03-08
7
268 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
Netscaler Common Configuration How To guides

If you use NetScaler you will want to see these guides. The NetScaler How To Guides show administrators how to get NetScaler up and configured by providing instructions for common scenarios and some not so common ones.

 
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 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

Complete VMware vSphere® ESX(i) & Hyper-V Backup

Capture your entire system, including the host, with patented disk imaging integrated with VMware VADP / Microsoft VSS and RCT. RTOs is as low as 15 seconds with Acronis Active Restore™. You can enjoy unlimited P2V/V2V migrations from any source (even from a different hypervisor)

Question has a verified solution.

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

APEX (Application Express) is used to develop a web application from Oracle. SQL Workshop is one of the tools that comes with Oracle APEX to query or modify the database objects or to make any changes to the structure.
These days, all we hear about hacktivists took down so and so websites and retrieved thousands of user’s data. One of the techniques to get unauthorized access to database is by performing SQL injection. This article is quite lengthy which gives bas…
In Microsoft Access, learn different ways of passing a string value within a string argument. Also learn what a “Type Mis-match” error is about.
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…

864 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

21 Experts available now in Live!

Get 1:1 Help Now