Results 1 to 9 of 9

Thread: Query Help

  1. #1

    Thread Starter
    Junior Member vks.gautam1's Avatar
    Join Date
    Dec 2008
    Location
    Chandigarh, India
    Posts
    27

    Question Query Help

    Im Using vb.net & msacces.

    wt i want to upload data in Datgridview.


    Code:

    select * from Table name where KtDate<Date
    How can i select that data which is two months back of current date

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

    Re: Query Help

    select * from Table name where KtDate< #DateAdd(mm,-2,Date())#
    Sometimes the Programmer
    Sometimes the DBA

    Mazz1

  3. #3

    Thread Starter
    Junior Member vks.gautam1's Avatar
    Join Date
    Dec 2008
    Location
    Chandigarh, India
    Posts
    27

    Re: Query Help

    It is not working .

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

    Re: Query Help

    That doesn't tell us much... is there an error message? (if so, what?) does it return the wrong data? something else?

    I can see that Gary made a minor mistake, the # characters shouldn't be there. You may also need to change mm to "m"

  5. #5

    Thread Starter
    Junior Member vks.gautam1's Avatar
    Join Date
    Dec 2008
    Location
    Chandigarh, India
    Posts
    27

    Re: Query Help

    I m pasting this code < DateAdd(m,-2,Date())

    should there any changes in given code. I Tried MSDN help & other also but nothing happens

    But it is giving following error.

    No value given for one or more required parameters

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

    Re: Query Help

    The quote characters are important (note that you can use either " or ' ).

  7. #7

    Thread Starter
    Junior Member vks.gautam1's Avatar
    Join Date
    Dec 2008
    Location
    Chandigarh, India
    Posts
    27

    Re: Query Help

    It is not working.

    "select * from tableName where ColumnName<DateAdd(m,-2,Date())"

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

    Re: Query Help

    Code:
    "select * from tableName where ColumnName<DateAdd('m',-2,Date())"

  9. #9

    Thread Starter
    Junior Member vks.gautam1's Avatar
    Join Date
    Dec 2008
    Location
    Chandigarh, India
    Posts
    27

    Re: Query Help

    Thanks.. It is working.

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