Results 1 to 3 of 3

Thread: Still having troubles With dates in SQL

  1. #1

    Thread Starter
    Junior Member
    Join Date
    Jun 2005
    Posts
    26

    Question Still having troubles With dates in SQL

    Thanks for your help earlier szlamany.

    SQL is so crazy. You have to get it right on or it doesn't work.

    How do I handle it the SQL date with a variable?

    I'm still getting type mismatch.

    Code:
      Dim dteDate As Date
          dteDate = "#08/13/2004#"
          'sql="SELECT * FROM DAILY_SALES_HIST_X WHERE DlvryDte=#8/13/2004#" 'IT WORKS!
          'sql="SELECT * FROM DAILY_SALES_HIST_X WHERE CustomerId='010110'"   'IT WORKS!
          sql="SELECT * FROM DAILY_SALES_HIST_X WHERE DlvryDte='dteDate'"
    Help Please
    Thanks

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

    Re: Still having troubles With dates in SQL

    For that (or any other kind of variable) you just need to do this:

    sql="SELECT * FROM DAILY_SALES_HIST_X WHERE DlvryDte='" & dteDate & "'"

  3. #3
    MS SQL Powerposter szlamany's Avatar
    Join Date
    Mar 2004
    Location
    Connecticut
    Posts
    18,263

    Re: Still having troubles With dates in SQL

    SI - this is a bit of a double post - see this other thread...

    http://www.vbforums.com/showthread.p...10#post2084210

    *** Read the sticky in the DB forum about how to get your question answered quickly!! ***

    Please remember to rate posts! Rate any post you find helpful - even in old threads! Use the link to the left - "Rate this Post".

    Some Informative Links:
    [ SQL Rules to Live By ] [ Reserved SQL keywords ] [ When to use INDEX HINTS! ] [ Passing Multi-item Parameters to STORED PROCEDURES ]
    [ Solution to non-domain Windows Authentication ] [ Crazy things we do to shrink log files ] [ SQL 2005 Features ] [ Loading Pictures from DB ]

    MS MVP 2006, 2007, 2008

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