Database Query

I'm trying to query an SQL Server 2000 database using a where clause in an ASP page and its giving me a syntax error. Can anyone see why?

Code:
' Initialize String. (This is where I put the SQL Statement)
strSQL = "SELECT [Date], "
strSQL = strSQL & "[Name], "
strSQL = strSQL & "[Event], "
strSQL = strSQL & "[TimeOut], "
strSQL = strSQL & "[TimeBack], "
strSQL = strSQL & "[ContactNumber], "
strSQL = strSQL & "[EventID] "
strSQL = strSQL & "FROM [EventTable] "
strSQL = "WHERE [Date] = " & "'" & strDateInUse & "'"

The error message:
WHERE [Date] = '7/2/2002'
Failed to Get Directory...
Error Number: -2147217900
Error Description: Incorrect syntax near the keyword 'WHERE'.

Thanks

Comments

  • Change this line from
    strSQL = "WHERE [Date] = " & "'" & strDateInUse & "'"

    To
    strSQL = strSQL & "WHERE [Date] = " & "'" & strDateInUse & "'"

    : I'm trying to query an SQL Server 2000 database using a where clause in an ASP page and its giving me a syntax error. Can anyone see why?
    :
    : Code:
    : ' Initialize String. (This is where I put the SQL Statement)
    : strSQL = "SELECT [Date], "
    : strSQL = strSQL & "[Name], "
    : strSQL = strSQL & "[Event], "
    : strSQL = strSQL & "[TimeOut], "
    : strSQL = strSQL & "[TimeBack], "
    : strSQL = strSQL & "[ContactNumber], "
    : strSQL = strSQL & "[EventID] "
    : strSQL = strSQL & "FROM [EventTable] "
    : strSQL = "WHERE [Date] = " & "'" & strDateInUse & "'"
    :
    : The error message:
    : WHERE [Date] = '7/2/2002'
    : Failed to Get Directory...
    : Error Number: -2147217900
    : Error Description: Incorrect syntax near the keyword 'WHERE'.
    :
    : Thanks
    :
    :

Sign In or Register to comment.

Howdy, Stranger!

It looks like you're new here. If you want to get involved, click one of these buttons!

Categories

In this Discussion