SQL Server ASP Syntax error

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • Paul

    SQL Server ASP Syntax error

    Hi,

    I'm new to ASP and have stumbled across what appears to be a common
    problem, but after trying several solutions from other posts I've had
    no luck. My SQL SELECT statement is fine elsewhere (e.g. in ACCESS),
    but when executed from ASP I get this syntax error:

    Error Type:
    Microsoft OLE DB Provider for ODBC Drivers (0x80040E14)
    [Microsoft][ODBC SQL Server Driver][SQL Server]Line 1: Incorrect
    syntax near '16'.
    /forecast/test.asp, line 27

    (line 27 is where the date is in the HAVING part of the statement)

    Here is the Statement:
    ----------------------

    SELECT dbo_ForecastIn. DataTime AS E_Time, dbo_ForecastInD ata.DataTime
    AS FD_Time, dbo_ForecastInD ata.WindFarmPow er AS ForecastPower FROM
    dbo_ForecastIn INNER JOIN dbo_ForecastInD ata ON dbo_ForecastIn. DataID
    = dbo_ForecastInD ata.DataID GROUP BY dbo_ForecastIn. DataTime,
    dbo_ForecastInD ata.DataTime, dbo_ForecastInD ata.WindFarmPow er HAVING
    dbo_ForecastIn. DataTime = #06/02/2004 16:00:00# ORDER BY
    dbo_ForecastIn. DataTime, dbo_ForecastInD ata.DataTime;

    Here is the code:
    -----------------

    SQLStmt = "SELECT dbo_ForecastIn. DataTime AS E_Time,
    dbo_ForecastInD ata.DataTime AS FD_Time,
    dbo_ForecastInD ata.WindFarmPow er AS ForecastPower "
    SQLStmt = SQLStmt & "FROM dbo_ForecastIn INNER JOIN
    dbo_ForecastInD ata ON dbo_ForecastIn. DataID =
    dbo_ForecastInD ata.DataID "
    SQLStmt = SQLStmt & "GROUP BY dbo_ForecastIn. DataTime,
    dbo_ForecastInD ata.DataTime, dbo_ForecastInD ata.WindFarmPow er "
    SQLStmt = SQLStmt & "HAVING dbo_ForecastIn. DataTime = #06/02/2004
    16:00:00# "
    SQLStmt = SQLStmt & "ORDER BY dbo_ForecastIn. DataTime,
    dbo_ForecastInD ata.DataTime;"
    response.write( SQLStmt)
    Set RS = Connection.Exec ute(SQLStmt)

    Hope one of you geniuses can sort me out.

    Thanks.
  • John Bell

    #2
    Re: SQL Server ASP Syntax error

    Hi Paul

    Access SQL and SQL Server SQL have different syntaxes one of which is
    deliminating dates. Use Quotes around the dates instead of the hashes.

    If you used SQL Profiler you may see the exact statement being sent to SQL
    Server, you can then cut and paste it into Query Analyser to get it to work!

    John

    "Paul" <no_ssh@yahoo.c o.uk> wrote in message
    news:45a2d774.0 406230345.622b4 9be@posting.goo gle.com...[color=blue]
    > Hi,
    >
    > I'm new to ASP and have stumbled across what appears to be a common
    > problem, but after trying several solutions from other posts I've had
    > no luck. My SQL SELECT statement is fine elsewhere (e.g. in ACCESS),
    > but when executed from ASP I get this syntax error:
    >
    > Error Type:
    > Microsoft OLE DB Provider for ODBC Drivers (0x80040E14)
    > [Microsoft][ODBC SQL Server Driver][SQL Server]Line 1: Incorrect
    > syntax near '16'.
    > /forecast/test.asp, line 27
    >
    > (line 27 is where the date is in the HAVING part of the statement)
    >
    > Here is the Statement:
    > ----------------------
    >
    > SELECT dbo_ForecastIn. DataTime AS E_Time, dbo_ForecastInD ata.DataTime
    > AS FD_Time, dbo_ForecastInD ata.WindFarmPow er AS ForecastPower FROM
    > dbo_ForecastIn INNER JOIN dbo_ForecastInD ata ON dbo_ForecastIn. DataID
    > = dbo_ForecastInD ata.DataID GROUP BY dbo_ForecastIn. DataTime,
    > dbo_ForecastInD ata.DataTime, dbo_ForecastInD ata.WindFarmPow er HAVING
    > dbo_ForecastIn. DataTime = #06/02/2004 16:00:00# ORDER BY
    > dbo_ForecastIn. DataTime, dbo_ForecastInD ata.DataTime;
    >
    > Here is the code:
    > -----------------
    >
    > SQLStmt = "SELECT dbo_ForecastIn. DataTime AS E_Time,
    > dbo_ForecastInD ata.DataTime AS FD_Time,
    > dbo_ForecastInD ata.WindFarmPow er AS ForecastPower "
    > SQLStmt = SQLStmt & "FROM dbo_ForecastIn INNER JOIN
    > dbo_ForecastInD ata ON dbo_ForecastIn. DataID =
    > dbo_ForecastInD ata.DataID "
    > SQLStmt = SQLStmt & "GROUP BY dbo_ForecastIn. DataTime,
    > dbo_ForecastInD ata.DataTime, dbo_ForecastInD ata.WindFarmPow er "
    > SQLStmt = SQLStmt & "HAVING dbo_ForecastIn. DataTime = #06/02/2004
    > 16:00:00# "
    > SQLStmt = SQLStmt & "ORDER BY dbo_ForecastIn. DataTime,
    > dbo_ForecastInD ata.DataTime;"
    > response.write( SQLStmt)
    > Set RS = Connection.Exec ute(SQLStmt)
    >
    > Hope one of you geniuses can sort me out.
    >
    > Thanks.[/color]


    Comment

    Working...