select statement error

  • I am running the following queries:

    SQLstr = "Select Distinct TM from PCTTS_TIME_Results where Dept = " + Me.DropDownListDept.SelectedValue.ToString + " order by TM"

    It continues to return the message, "Incorrect syntax near keyword 'order'. Any advice.

    Thanks,

    Verlin Taylor

  • Whatever you're using (vb.net) ... print your SQLstr to see what it's actually sending to the SQL Server. I'm guessing that it is not resolving Me.DropDownListDept.SelectedValue.ToString to what you think it is.

    └> bt



    Forum Etiquette: How to post data/code on a forum to get the best help[/url]

  • Dept is probably a string, and thus needs to be enclosed in quotes.

    SQLstr = "Select Distinct TM from PCTTS_TIME_Results where Dept = '" + Me.DropDownListDept.SelectedValue.ToString + "' order by TM"

    ^ ^

    Wayne
    Microsoft Certified Master: SQL Server 2008
    Author - SQL Server T-SQL Recipes


    If you can't explain to another person how the code that you're copying from the internet works, then DON'T USE IT on a production system! After all, you will be the one supporting it!
    Links:
    For better assistance in answering your questions
    Performance Problems
    Common date/time routines
    Understanding and Using APPLY Part 1 & Part 2

  • That was it.

    Thanks,

    Verlin T.

Viewing 4 posts - 1 through 3 (of 3 total)

You must be logged in to reply to this topic. Login to reply