Go Premium for a chance to win a PS4. Enter to Win

x
?
Solved

SQL Query

Posted on 2014-01-13
2
Medium Priority
?
351 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 27

Accepted Solution

by:
Shaun Kline earned 2000 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

Important Lessons on Recovering from Petya

In their most recent webinar, Skyport Systems explores ways to isolate and protect critical databases to keep the core of your company safe from harm.

Question has a verified solution.

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

I have a large data set and a SSIS package. How can I load this file in multi threading?
This article shows gives you an overview on SQL Server 2016 row level security. You will also get to know the usages of row-level-security and how it works
This video shows, step by step, how to configure Oracle Heterogeneous Services via the Generic Gateway Agent in order to make a connection from an Oracle session and access a remote SQL Server database table.
This video shows how to set up a shell script to accept a positional parameter when called, pass that to a SQL script, accept the output from the statement back and then manipulate it in the Shell.

877 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