Want to protect your cyber security and still get fast solutions? Ask a secure question today.Go Premium

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 419
  • Last Modified:

SQL - Dates syntax ( VB6 connecting to SQL Server database)

Hi Experts

I'm trying to update a table with new [Test Requests]. It's in VB6, connecting to a SQL database and it's designed to select tests, requested after the [lastupdate] date. Just a syntax assist on the troublesome line.

eg
LastUpdate = "21/12/2009"

'select most recent tests
    rs.CursorLocation = adUseClient
    Sql = ""
    Sql = Sql & " Select * from REQUESTEDTESTS " 
    'Sql = Sql & " where convert(varchar, [requestdate],120) > " .........datevalue(LastUpdate)??


    'some examples of what i have tried
   
    '/Sql = Sql & " where convert(varchar, [requestdate],120) > " & DateValue(LastUpdate) ' conversion failed
    '/Sql = Sql & " where convert(varchar, [requestdate],120) > convert(varchar, [lastupdate],120)" 'invalid column
    '/Sql = Sql & " where convert(varchar, [requestdate],120) > getdate(lastupdate)" 'doesn't work

    rs.Open Sql, cn




Much appreciated.
PD
0
peterdarazs
Asked:
peterdarazs
1 Solution
 
game-masterCommented:


try something like this...

sql = "Select * from YourTable where cast(requestdate as dateTime) > cast('" & LastUpdate & "',as Datetime)"



game-master
0
 
SharathData EngineerCommented:
try this if both requestdate and lastupdate are of datetime type.

 '/Sql = Sql & " where requestdate > lastupdate"
0
 
peterdarazsAuthor Commented:
1/ Game-master
sql = "Select * from TESTREQUESTS where cast(requestdate as dateTime) > cast('" & LastUpdate & "',as Datetime)"  ' ..........Syntax error near 'as'  ( i have also tried placing a space between , and the second 'as')  

2/ Sharath -
I changed it to ".........RequestDate > '" & LastUpdate & "'" and IT WORKED . Grateful for the help.

siThanks

0

Featured Post

Free Tool: SSL Checker

Scans your site and returns information about your SSL implementation and certificate. Helpful for debugging and validating your SSL configuration.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Tackle projects and never again get stuck behind a technical roadblock.
Join Now