Hi,
I'm trying to write some VBA script which uses date in an SQL statement: -
SQL1 = "INSERT INTO Contractrealisatie (Medewerker,Uren) SELECT Planning.Werknemer, (15*(Planning.[Stoptijd] - Planning.[Aanvangstijd])) FROM Planning WHERE ([Datum] = " & CorrectedDate & ")"
-
This however does not work; when the WHERE conditiion should be true, it always results in 0 appends.
What is wrong here?
CorrectDate is a date-typed variable.
Thanks!
6 7192
Hi,
I'm trying to write some VBA script which uses date in an SQL statement: -
SQL1 = "INSERT INTO Contractrealisatie (Medewerker,Uren) SELECT Planning.Werknemer, (15*(Planning.[Stoptijd] - Planning.[Aanvangstijd])) FROM Planning WHERE ([Datum] = " & CorrectedDate & ")"
-
This however does not work; when the WHERE conditiion should be true, it always results in 0 appends.
What is wrong here?
CorrectDate is a date-typed variable.
Thanks!
Look at the FORMAT function in how you should be dealing with your date formatting for your SELECTS and UPDATES compared with the internal storage of your data. You will find that you merely need to swap the month and day round when using code
Format(CorrectedDate, "mm/dd/yyyy")
Jim
Also, whenever comparing date literals, they need to be wrapped in #'s...
Regards,
Scott
Look at the FORMAT function in how you should be dealing with your date formatting for your SELECTS and UPDATES compared with the internal storage of your data. You will find that you merely need to swap the month and day round when using code
Format(CorrectedDate, "mm/dd/yyyy")
Jim
Hi Jim,
Thanks for your help!
I fiddled around a bit with the format function, but, I cannot get it to work, whatever I try. I even tried to manually add a date (in different formats) in my SQL query, but I always get a empty result! When I replace the Datum field by another column, it all works well.
Any guesses?
Thanks agian!
Hi Jim,
Thanks for your help!
I fiddled around a bit with the format function, but, I cannot get it to work, whatever I try. I even tried to manually add a date (in different formats) in my SQL query, but I always get a empty result! When I replace the Datum field by another column, it all works well.
Any guesses?
Thanks agian!
Without analysing your table structure, data, and actually seeing what it is you are doing then my guess being blind here here is not much help unfortunately.
If you run the first bit of your query as a 'Select' I take it you do have records available in order to do the insert. Try running the select on its own to make sure the 'SELECT' is reading correctly. Failing that the only other option would be to post your table structure. Exact query syntax and a few records of sample data you have there and I could see if I can replicate it this end?
SELECT Planning.Werknemer, (15*(Planning.[Stoptijd] - Planning.[Aanvangstijd])) FROM Planning WHERE ([Datum] = #" & CorrectedDate & "#)"
Without analysing your table structure, data, and actually seeing what it is you are doing then my guess being blind here here is not much help unfortunately.
If you run the first bit of your query as a 'Select' I take it you do have records available in order to do the insert. Try running the select on its own to make sure the 'SELECT' is reading correctly. Failing that the only other option would be to post your table structure. Exact query syntax and a few records of sample data you have there and I could see if I can replicate it this end?
SELECT Planning.Werknemer, (15*(Planning.[Stoptijd] - Planning.[Aanvangstijd])) FROM Planning WHERE ([Datum] = #" & CorrectedDate & "#)"
As a PS I am on vacation as of today (off to sunny cyprus) so if you don't get a resolution you can PM me and I'll continue on return next week?
Jim
Thanks guys!!! I solved it by adding the #'s! How stupid of me!
Cya!
Sign in to post your reply or Sign up for a free account.
Similar topics
by: F |
last post by:
Hi
I have posted the question few days back about problem in inserting the
dates in SQL server and thankful to them who replied.
That was solved and this is a nice solution....
|
by: Mike N. |
last post by:
I am currently using a function to validate a form on the client side
(see code below). At the end of the function, I would like it to also
compare a startDate against an endDate to ensure that the...
|
by: Duppypog |
last post by:
I'm trying to compare a date stored in a database with today's date using an
If statement, but it's not returning true. Example, value in database is
11/5/2003 with today being 11/6/2003. Can...
|
by: Philip Townsend |
last post by:
I am having difficulty with a simple routine as follows:
public static bool VerifyExpirationDate(DateTime date)
{
if(date>=DateTime.Now)return true;
else return false;
}
The problem is that...
|
by: Manny Chohan |
last post by:
Hi, i have two datetime values in format 11/22/04 9:00 AM and 11/22/04 9:30
AM. How can i compare dates .net c# or if there is any other way such as
Javascript.
Thanks
Manny
|
by: ameshkin |
last post by:
Hi GUys,
Im trying to compare two dates in MYSQL. But its not treating the
dates as numbers, but as strings. I try using strtotime but that did
not work.
Basically, if the last comment is...
|
by: colincolehour |
last post by:
I am new to Python and am working on my first program. I am trying to
compare a date I found on a website to todays date. The problem I have
is the website only shows 3 letter month name and the...
|
by: cheryl |
last post by:
I am using the PHP.MYSQL and Apache server application in developing my website. I have problem in comparing dates. Website has room reservation, the user will check first the room availability. The...
|
by: dantebothermy |
last post by:
Is there a simple way to subtract the time from a datetime field, so when I compare dates, I'm always comparing the dates at 12:00 am?
I'd really prefer not to convert all my dates to strings.
...
|
by: jupi13 |
last post by:
i have this code..i don't know what where is the error in this one..it says data type mismatch.....
Dim Mydate As Date
Dim MydateString As String
MydateString = "Text1.Text"
Mydate =...
|
by: BarryA |
last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
|
by: nemocccc |
last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
|
by: Hystou |
last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
|
by: Oralloy |
last post by:
Hello folks,
I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>".
The problem is that using the GNU compilers,...
|
by: jinu1996 |
last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
|
by: Hystou |
last post by:
Overview:
Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
|
by: tracyyun |
last post by:
Dear forum friends,
With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
|
by: agi2029 |
last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
|
by: isladogs |
last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM).
In this session, we are pleased to welcome a new...
| |