Computer Learning Zone CLZ Access Excel Word Windows

I don't know why people who have not been on rockets continue to ask, "you're not scared?" No we were not scared... until something happens, then it's time to get scared.

-Buzz Aldrin
 
Home   Courses   TechHelp   Forums   Help   Contact   Merch   Join   Order   Logon  
 
Back to Active Server Pages Forum    Comments List
Upload Images   @Reply   Bookmark    Link   Email   Next Unseen 
Second SQL
Diane Stankevitz 
     
4 years ago
Hello Everyone at Computer Learning Zone,

I have another question. I am trying to create a second SQL, I have written the code as such:

%><!--#include file="database-connect.asp"--><%
SQL = "SELECT * FROM TeamT Where Sport='Wrestling' AND Active='-1'"
RS.Open SQL, Conn

Set RS2 = Server.CreateObject("ADODB.Recordset")
SQL2 = "SELECT * FROM AthleteT WHERE AthleteID=" & AthleteID
RS2.Open SQL2, Conn

AthleteInfo = RS2("LastName") & ", " & RS2("FirstName") & " " & RS2("SID")
RS2.Close
Set RS2 = Nothing

But when I try to go to that page I get the following message:

Microsoft OLE DB Provider for SQL Server error '80040e14'

Incorrect syntax near '='.

When I remove the WHERE clause from SQL 2, it seems to work except the only one name appears in all the rows, but when I click on the hyperlink on the ID it shows the correct information for that person.

Can someone help?

Thank you so much. :-)
Alex Hedley  @Reply  
           
4 years ago
Is AthleteID a number?

If you hardcore the ID does it work?
"SELECT * FROM AthleteT WHERE AthleteID=1"
Replace 1 with an existing ID
Richard Rost  @Reply  
          
4 years ago
I think the problem is Active. If that's a Y/N value in SQL Server it's either 0 or 1, not -1, and it shouldn't be in quotes.

SQL = "SELECT * FROM TeamT Where Sport='Wrestling' AND Active=1"

One of the hardest things about switching from Access to SQL Server is remember the different syntax.
Diane Stankevitz OP  @Reply  
     
4 years ago
Changing the Y/N values to either 0 or 1, with or without quotes was not the issue. I even removed that WHERE clause altogether, and it wasn't the problem. Changing the AthleteID to 1 only should the first athlete in the database.
Alex Hedley  @Reply  
           
4 years ago
Of course it did, because that's what you're asking it to do,
Where is AthleteID coming from? A Query string?
Kevin Robertson  @Reply  
          
4 years ago
Where is AthleteID from? Is it from the first Recordset?
If so try this.

SQL2 = "SELECT * FROM AthleteT WHERE AthleteID=" & RS("AthleteID")
Diane Stankevitz OP  @Reply  
     
4 years ago
Hi Kevin, when I added & RS("AthleteID") it gave me one name, however, it was at least the first person on the list I needed. It is the information from another table.

Alex, the AthleteID coming from a second Query string.

All this was working fine when I was using an uploaded database, but I started having problems when I switch to using SQL on the server.
Alex Hedley  @Reply  
           
4 years ago
I don't think we have the full picture

Where's the loop to show all of them?

What's the purpose of the page?
Get all active Wrestlers then display them in a list?
Richard Rost  @Reply  
          
4 years ago
Definitely need a loop for that.
Diane Stankevitz OP  @Reply  
     
4 years ago
Yes, to get all active Wrestlers then display them in a list?
Diane Stankevitz OP  @Reply  
     
4 years ago
Here is the entire page:

<!--#include file="header_athletes.asp"-->
<!--#include file="security_check.asp"-->

<BR>
<%
Sort = Request("Sort")
If Sort = "" Then
Sort = "AthleteID"
ElseIf Sort = "LastName" Then
Sort = "LastName, FirstName"
ElseIf Sort = "FirstName" Then
Sort = "FirstName"
ElseIf Sort = "SID" Then
Sort = "SID"
ElseIf Sort = "DOB" Then
Sort = "DOB"
Else
Sort = "AthleteID"
End if
%><!--#include file="database-connect.asp"--><%
SQL = "SELECT * FROM TeamT Where Sport='Wrestling' AND Active='-1'"
RS.Open SQL, Conn

Set RS2 = Server.CreateObject("ADODB.Recordset")
SQL2 = "SELECT * FROM AthleteT WHERE AthleteID=" & RS("AthleteID")
RS2.Open SQL2, Conn

AthleteInfo = RS2("LastName") & ", " & RS2("FirstName") & " " & RS2("SID")
RS2.Close
Set RS2 = Nothing

response.write "<div align=center>"
response.write "<TABLE border=1 width=800 cellspacing=0>"
response.write "<TR bgcolor='#009900'>"

URL = "wrestling_roster_eligible.asp"
URL2 = "wrestling_
Richard Rost  @Reply  
          
4 years ago
Yeah, you need a while loop.

while not rs2.eof
   ' do stuff here
   rs.movenext
wend

Diane Stankevitz OP  @Reply  
     
4 years ago
I will try this. Thank you!!!!!
Diane Stankevitz OP  @Reply  
     
4 years ago
That doesn't seem to be working either. :-(
Diane Stankevitz OP  @Reply  
     
4 years ago
Before when I was just using the Database, it worked just fine. Now that I am using the SQL server, that is when the issues started. I used to just use a query, now I must do things from the table.
Adam Schwanz  @Reply  
           
4 years ago
Is there only one record in AthleteT for each AthleteID?

What does not working mean? Any errors or wrong/missing information displayed?
Diane Stankevitz OP  @Reply  
     
4 years ago
Yes, one record in AthleteT for each AthleteID?
Alex Hedley  @Reply  
           
4 years ago
Think there's a typo

rs.movenext => rs2.movenext

while not rs2.eof
   ' do stuff here
   rs2.movenext
wend
Diane Stankevitz OP  @Reply  
     
4 years ago
Yes, I did fix that
Alex Hedley  @Reply  
           
4 years ago
What did you add to your loop?
The 'do stuff here' bit

This thread is now CLOSED. If you wish to comment, start a NEW discussion in Active Server Pages Forum.
 

Next Unseen

 
New Feature: Comment Live View
 
 

The following is a paid advertisement
Computer Learning Zone is not responsible for any content shown or offers made by these ads.
 

Learn
 
Access - index
Excel - index
Word - index
Windows - index
PowerPoint - index
Photoshop - index
Visual Basic - index
ASP - index
Seminars
More...
Customers
 
Login
My Account
My Courses
Lost Password
Memberships
Student Databases
Change Email
Info
 
Latest News
New Releases
User Forums
Topic Glossary
Tips & Tricks
Search The Site
Code Vault
Collapse Menus
Help
 
Customer Support
Web Site Tour
FAQs
TechHelp
Consulting Services
About
 
Background
Testimonials
Jobs
Affiliate Program
Richard Rost
Free Lessons
Mailing List
PCResale.NET
Order
 
Video Tutorials
Handbooks
Memberships
Learning Connection
Idiot's Guide to Excel
Volume Discounts
Payment Info
Shipping
Terms of Sale
Contact
 
Contact Info
Support Policy
Mailing Address
Phone Number
Fax Number
Course Survey
Email Richard
[email protected]
Blog RSS Feed    YouTube Channel

LinkedIn
Copyright 2026 by Computer Learning Zone, Amicron, and Richard Rost. All Rights Reserved. Current Time: 5/6/2026 2:54:14 PM. PLT: 0s