format date issue

Author Message
tombino

  • Total Posts : 2
  • Scores: 0
  • Reward points : 0
  • Joined: 2/6/2008
  • Status: offline
format date issue Wednesday, February 06, 2008 11:57 AM (permalink)
0
Hi,

I have a problem doing a query in ASP. This is my query:

Dim vardate
vardate = "#" & latestdate & "#"

sSQL1 = "SELECT tbl_size.sizename, tbl_stylesize.sizeid, tbl_stylesize.rate, tbl_stylesize.changedate " & _
"FROM tbl_stylesize " & _
"INNER JOIN tbl_size " & _
"ON tbl_stylesize.sizeid = tbl_size.sizeid " & _
"WHERE tbl_stylesize.active = -1 " & _
" AND FORMAT (vardate, "mm/dd/yyyy" ) = tbl_stylesize.changedate " & _
" AND tbl_stylesize.styleid = " & arrItem & _
" ORDER BY tbl_size.sizeid"

The problem is the " (ando may be also /)in the FORMAT date. It reconize it like a end of statement. I tryed to write

"" & mm & "/" & dd & "/" & yyyy & """ or
Chr(34) & mm/dd/yyyy & Chr(34)

but anything is working.
Can you please help me?

Best Regards,
Tom
 
#1
    centauricw

    • Total Posts : 42
    • Scores: 2
    • Reward points : 0
    • Joined: 2/20/2006
    • Status: offline
    RE: format date issue Wednesday, February 06, 2008 5:28 PM (permalink)
    0
    Here is how craft your SQL query correctly:

    sSQL1 = "SELECT tbl_size.sizename, tbl_stylesize.sizeid, tbl_stylesize.rate, tbl_stylesize.changedate " & _
    "FROM tbl_stylesize " & _
    "INNER JOIN tbl_size " & _
    "ON tbl_stylesize.sizeid = tbl_size.sizeid " & _
    "WHERE tbl_stylesize.active = -1 " & _
    " AND '" & FormatDate(vardate, vbShortDate) & "' = tbl_stylesize.changedate " & _
    " AND tbl_stylesize.styleid = " & arrItem & _
    " ORDER BY tbl_size.sizeid"

    Notice I took the SQL FORMAT command out because you actually crafting a SQL query with a literal date (the variable "vardate" is a VBScript variable, not a SQL variable).  I inserted the VBScript DateFormat command to return a short date string that SQL Server will understand and I surrounded the date with single-quotes to tell SQL this is a literal value.

    Regards,

     
    #2
      tombino

      • Total Posts : 2
      • Scores: 0
      • Reward points : 0
      • Joined: 2/6/2008
      • Status: offline
      RE: format date issue Thursday, February 07, 2008 11:21 AM (permalink)
      0
       
      Thank you centauricw, this solved my problem.
       
      I didnt know the existence of vbshortdate, I am pretty new in VbScript.
       
       
      Best Regards,
      Tom
       
       
       
      #3

        Online Bookmarks Sharing: Share/Bookmark

        Jump to:

        Current active users

        There are 0 members and 1 guests.

        Icon Legend and Permission

        • New Messages
        • No New Messages
        • Hot Topic w/ New Messages
        • Hot Topic w/o New Messages
        • Locked w/ New Messages
        • Locked w/o New Messages
        • Read Message
        • Post New Thread
        • Reply to message
        • Post New Poll
        • Submit Vote
        • Post reward post
        • Delete my own posts
        • Delete my own threads
        • Rate post

        2000-2012 ASPPlayground.NET Forum Version 3.9