0

I've written an SQL select statement. I've checked te statement in SQL Server Management Studio Express and it works greate. When I go take the code to my asp page and insert it, I get a generic IIS 500 error. When I take out my variable I'm tyring to use, it works just fine. I've written the response out and it shows the correct data. Here is my code.

<%
    CurrentYear = Year(Date)
    UserID = Request.QueryString("id")

    sqlCOURSES = "SELECT syl.id AS sid, d.dept AS department, syl.course_name AS cname, syl.classroom_number AS room, syl.course_number AS cnumber, syl.section_number AS snumber, syl.semester_year yr, sem.semester AS semester, syl.class_DaysTimes AS dt, l.Name building FROM tbl_Syllabus AS syl LEFT OUTER JOIN tbl_departments AS d ON syl.dept_ID = d.ID LEFT OUTER JOIN tbl_semester AS sem ON syl.semester = sem.ID LEFT OUTER JOIN tbl_locations AS l ON syl.building = l.id WHERE syl.people_ID = '" + UserID + "' AND syl.semester_year = " + CurrentYear + " ORDER BY sem.sort ASC"

%>

If I take the CurrentYear out of the code above and replace it with the year manually it works fine. When I put this code in, it displays the year just fine.

<%
    CurrentYear = Year(Date)

    response.write(CurrentYear)
%>
2
Contributors
6
Replies
20
Views
3 Years
Discussion Span
Last Post by JorgeM
0

You are missing the single quotes...

AND syl.semester_year = '" + CurrentYear + "' ORDER BY sem.sort ASC"
0

hmmm. im not seeing it at this moment by looking at your code. If in your query you manually have AND syl.semester_year = '2014' ORDER BY sem.sort ASC", its OK, then... ?

0

Using +'s instead of &'s is what was causing my issue. I've got it working fine now. Thanks for the help.

This question has already been answered. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.