Results 1 to 5 of 5

Thread: [RESOLVED] SQL Statement

  1. #1

    Thread Starter
    Junior Member
    Join Date
    Oct 2011
    Posts
    29

    Resolved [RESOLVED] SQL Statement

    Hi, i´ve a problem with a sql statement!!!

    This is my statement:
    strSQL2 = "SELECT ID,txamort,aamort FROM tbltx1987 where [ID]=" & Id
    strSQL2 = strSQL2 & "order by aamort asc"

    Gives me a sintaxe error '[ID]=1order by aamort asc'

    I have a TextBox were i write the Id. The first string gives me all records with ID=Id, in this case 1.

    Anyone can help me!!

  2. #2
    A SQL Server fool GaryMazzone's Avatar
    Join Date
    Aug 2005
    Location
    Dover,NH
    Posts
    7,493

    Re: SQL Statement

    You need to add a space infornt of the order by
    Sometimes the Programmer
    Sometimes the DBA

    Mazz1

  3. #3

    Thread Starter
    Junior Member
    Join Date
    Oct 2011
    Posts
    29

    Re: SQL Statement

    Quote Originally Posted by fmcpc View Post
    Hi, i´ve a problem with a sql statement!!!

    This is my statement:
    strSQL2 = "SELECT ID,txamort,aamort FROM tbltx1987 where [ID]=" & Id
    strSQL2 = strSQL2 & "order by aamort asc"

    Gives me a sintaxe error '[ID]=1order by aamort asc'

    I have a TextBox were i write the Id. The first string gives me all records with ID=Id, in this case 1.

    Anyone can help me!!
    Pleople you can close this thread

    I´m so stupid, lol
    I´ve been all afternoon trying to find some examples, and no one helped me out because the problem was easier...


    Try to find the changes i´ve done to my statement:

    Bad statement:
    strSQL2 = "SELECT ID,txamort,aamort FROM tbltx1987 where [ID]=" & Id
    strSQL2 = strSQL2 & "order by aamort asc"

    Good statement:
    strSQL2 = "SELECT ID,txamort,aamort FROM tbltx1987 where [ID]=" & Id
    strSQL2 = strSQL2 & " order by aamort asc"

    I will wait for an answer with the solution of the problem if anyone can see

  4. #4

    Thread Starter
    Junior Member
    Join Date
    Oct 2011
    Posts
    29

    Re: SQL Statement

    thanks for the quick answer, it was helpfull because i solved the problem 1 minute after i make this thread on forum

  5. #5
    A SQL Server fool GaryMazzone's Avatar
    Join Date
    Aug 2005
    Location
    Dover,NH
    Posts
    7,493

    Re: SQL Statement

    As I said in post #2 look at the second part of the SQL statement . In the first (Bad) post there is a missing space infront of the word order. In second (good) post there is a space.
    Sometimes the Programmer
    Sometimes the DBA

    Mazz1

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width