?
Solved

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

Posted on 2010-01-12
3
Medium Priority
?
414 Views
Last Modified: 2012-05-08
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
Comment
Question by:peterdarazs
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
3 Comments
 
LVL 13

Expert Comment

by:game-master
ID: 26300150


try something like this...

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



game-master
0
 
LVL 41

Accepted Solution

by:
Sharath earned 2000 total points
ID: 26300428
try this if both requestdate and lastupdate are of datetime type.

 '/Sql = Sql & " where requestdate > lastupdate"
0
 

Author Closing Comment

by:peterdarazs
ID: 31676476
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

Get MongoDB database support online, now!

At Percona’s web store you can order your MongoDB database support needs in minutes. No hassles, no fuss, just pick and click. Pay online with a credit card. Handle your MongoDB database support now!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

'Between' is such a common word we rarely think about it but in SQL it has a very specific definition we should be aware of. While most database vendors will have their own unique phrases to describe it (see references at end) the concept in common …
Background What I'm presenting in this article is the result of 2 conditions in my work area: We have a SQL Server production environment but no development or test environment; andWe have an MS Access front end using tables in SQL Server but we a…
Get people started with the utilization of class modules. Class modules can be a powerful tool in Microsoft Access. They allow you to create self-contained objects that encapsulate functionality. They can easily hide the complexity of a process from…
This lesson covers basic error handling code in Microsoft Excel using VBA. This is the first lesson in a 3-part series that uses code to loop through an Excel spreadsheet in VBA and then fix errors, taking advantage of error handling code. This l…
Suggested Courses

764 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question