Solved

SQL Query

Posted on 2014-01-13
2
342 Views
Last Modified: 2014-01-13
I'm trying to display the number of Compliments by month but I get the "Expected end of statement" error message.
I would appreciate your help:
i=1

do while i<=12
    sql2013 = "SELECT Count(ID) AS CountID FROM Compliments where year("OccDate")='2013' and month("OccDate")=i"
    Set rs2013 = conn.Execute(sql2013)

    compliments= rs2013("CountID")
    response.write MonthName(i) & rs2013("CountID")
    i=i+1

loop


j=1

do while j<=12
    sql2014 = "SELECT Count(ID) AS CountID FROM Compliments where year("OccDate")='2014' and month("OccDate")=j"
    Set rs2014 = conn.Execute(sql2014)

    compliments= rs2014("CountID")
    response.write MonthName(i) & rs2014("CountID")
    j=j+1

loop

Open in new window

0
Comment
Question by:romsom
2 Comments
 
LVL 26

Accepted Solution

by:
Shaun Kline earned 500 total points
ID: 39777745
Line 4 and line 17 will error out because you have included "OccDate". The quote marks terminate the string. If OccDate is a field in your table, you do not need the quote marks.
0
 

Author Closing Comment

by:romsom
ID: 39777786
Thank you very much; problem solved!
0

Featured Post

Highfive Gives IT Their Time Back

Highfive is so simple that setting up every meeting room takes just minutes and every employee will be able to start or join a call from any room with ease. Never be called into a meeting just to get it started again. This is how video conferencing should work!

Join & Write a Comment

Suggested Solutions

This article explains how to reset the password of the sa account on a Microsoft SQL Server.  The steps in this article work in SQL 2005, 2008, 2008 R2, 2012, 2014 and 2016.
If you need to start windows update installation remotely or as a scheduled task you will find this very helpful.
Via a live example, show how to extract insert data into a SQL Server database table using the Import/Export option and Bulk Insert.
Viewers will learn how to use the UPDATE and DELETE statements to change or remove existing data from their tables. Make a table: Update a specific column given a specific row using the UPDATE statement: Remove a set of values using the DELETE s…

760 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

19 Experts available now in Live!

Get 1:1 Help Now