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

    Here`s my problem:


    aamort = Application.InputBox("Qual o ano q pretende imprimir?", Type:=1)

    strSQL1 = "SELECT ID,descricao,anoaq,valaq FROM tbltransfer where [anoaq]<=" & aamort
    strSQL1 = strSQL1 & " order by ID asc"
    rs1.Open "tbltransfer", cn, adOpenDynamic, adLockOptimistic, adCmdTable

    I want all records with anoaq<=aamort, where aamort is a variable asked at the user.

    But this statement returns all records!!

    why its returning the records with anoaq>aamort

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

    Re: Sql statement

    Because you are telling it to open a table (tbltransfer) as a table. That means everything in the table comes back
    Sometimes the Programmer
    Sometimes the DBA

    Mazz1

  3. #3
    Super Moderator si_the_geek's Avatar
    Join Date
    Jul 2002
    Location
    Bristol, UK
    Posts
    41,974

    Re: Sql statement

    You have set up strSQL1, but you aren't using it - the rs1.Open line just uses the table name.

    Change it to this:
    Code:
    rs1.Open strSQL1, cn, adOpenDynamic, adLockOptimistic, adCmdText

  4. #4

    Thread Starter
    Junior Member
    Join Date
    Oct 2011
    Posts
    29

    Re: Sql statement

    thanks guys, its working... to

  5. #5
    Super Moderator si_the_geek's Avatar
    Join Date
    Jul 2002
    Location
    Bristol, UK
    Posts
    41,974

    Re: Sql statement

    As you now have it sorted out, could you please do us a little favour, and mark the thread as Resolved?
    (this saves time reading for those of us who like to answer questions, and also helps those who search to find answers)

    You can do it by clicking on "Thread tools" just above the first post in this thread, then "Mark thread resolved". (like various other features of this site, you need JavaScript enabled in your browser for this to work).

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