Howdy, Stranger!

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

Categories

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

  • bosrbosr Member Posts: 13
    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
    :
    :

  • Shawn CarterShawn Carter Member Posts: 0

    _____ { http://forcoder.org } free video tutorials and ebooks about / Java, Swift, Delphi, Python, Objective-C, C#, Ruby, PHP, Visual Basic, Scratch, R, C++, JavaScript, PL/SQL, MATLAB, Assembly, C, Go, Perl, Visual Basic .NET Rust, FoxPro, Kotlin, Alice, ML, Logo, Clojure, Apex, D, Ada, F#, Scheme, COBOL, Hack, Prolog, Crystal, Scala, Lua, Fortran, ABAP, Transact-SQL, Bash, Julia, Awk, Dart, Lisp, VBScript, Erlang, LabVIEW, SAS / ____________

Sign In or Register to comment.