I am trying to correct the following query: - UPDATE marriages SET marriages.[Date of Marriage] = Format(CDate([Date of Marriage]),'m/d/yyyy')
-
-
WHERE marriages.[Date of Marriage] Is Not Null OR marriages.[Date of Marriage] <> 'VOID';
***What I am trying to do is change this so it will not try and update any records with a [Date of Marriage] value of 'VOID' and also will not try and update any records that have a [Date of Marriage] value of only the year for example '1917' or '1980'.
***
How could I go about changing this query to reflect what I want? I appreciate any help. Thanks.
20 1855
First a quick question. Is [Date of Marriage] a text field or a date field?
The example provided seems to suggest a text field, since you can have 'void' in your field.
How about Updating only if a valid Date exists, as in: - WHERE IsDate(marriages.[Date of Marriage])
You are correct. It is a text field.
But if a valid date exists then what would it actually be updating?
This would update only format then ?
I believe so.
But always take backup before you run a big update query if your not sure on the results :)
The problem I am having now is when I run the following query: - UPDATE marriages_cpy SET marriages_cpy.[Date of Marriage] = Format(CDate([Date of Marriage]),'m/d/yyyy')
-
WHERE marriages_cpy.[Date of Marriage] <> 'VOID' OR IsDate([Date of Marriage]);
-
Any records that have a [Date of Marriage] value of only a year like "1917" or "1980" or any that are not valid dates the values are deleted after running the query. However it does keep the VOID value. I do not want to delete any of the values that are not valid dates. I only want to skip those and not update them.
You just need to loose the <>Void part, since 1980 for example is different from void, and as such gets updated.
Since Void is not a valid date, the IsDate() criteria is enough for your needs. - UPDATE marriages_cpy SET marriages_cpy.[Date of Marriage] = Format(CDate([Date of Marriage]),'m/d/yyyy')
-
WHERE IsDate([Date of Marriage]);
So what would happen to a record that has a value of 1980 then? It would remain 1980 right ?
Yes 1980 would remain 1980. The query will only work on valid dates.
Yes you are right. I just tested it. Looks good. Any ideas as to why it was deleting the value before?
No I dont really see why it would be deleted. What I tried is this:
Alt-F11 to open VBE, then Ctrl-G to open/goto immediate pane.
Then I typed: - ? format("1980","m/d/yyyy")
which returned [6-2-1905] (Which is 1980 days after what VB counts as day 0 (12-30-1899)
So I could understand if 1980 got replaced by [6-2-1905], but it being deleted makes no real sense to me.
I don't understand why it returns the 6-2-1905. Could you explain this a little more for me. I would appreciate it. Thanks.
When a date gets stored, it gets stored as a double, and each time it gets retrieved, it gets formated back to a date.
For example Today is:Cdbl(Date())=40863
where as now() gives: cdbl(Now())=40863,9424768519
the 40863 represents the date, where as .9424768519 represents the time of the day, I presume, as a fraction of a full day, as you can see the day is almost over here :P.
From alot of views it makes sense to store the date as a number, because for instance its alot easier to do comparisions on whether or not a date is earlier (smaller) or later (greater) then another date. Im sure there are sites out there that explain it better then me though, so if your still unclear, go look it up. ;P
Edit: PS. Its just convention that says that 0 is 30/12/1899.
I have a better idea of what is happening now. Thanks for the explanation and the help.
Catalyst
NeoPa 32,556
Expert Mod 16PB Smiley:
PS. Its just convention that says that 0 is 30/12/1899.
It's not really a convention. It's just a date that MS decided to use.
NB. Because dates are stored as Doubles, they can also handle negative values so much older historical dates can also be represented by simply using negative numbers - ?CDate(-1),CDate(-657434)
-
29/12/1899 01/01/100
Your update query could be simply (fundamentally similar to other suggestions but slightly shorter) : - UPDATE [Marriages]
-
SET [Date of Marriage] = Format(CDate([Date of Marriage]),'m/d/yyyy')
-
WHERE IsDate([Date of Marriage])
Assuming your actual requirement is to update all date strings to the same format as long as they can be so updated, then ADezii's suggestion (from post #3) is a perfect solution for you.
Thanks for the input Neo. So far the update query is working for my situation. It is unusual how access handles the dates. I am definitely getting a better understanding of it though. Thanks again.
It's how all computers handle dates. An arbitrary date is chosen as the 0 date and every other date is relative to that date.
- UPDATE marriages SET marriages.[Date of Marriage] = Format(CDate([Date of Marriage]),'m/d/yyyy')
-
-
WHERE marriages.[Date of Marriage] Is Not Null OR marriages.[Date of Marriage]Or marriages.[CDate] <> 'VOID';
NeoPa 32,556
Expert Mod 16PB
@Sumon14
I'm not sure about that. It adds nothing to previous solutions and misses various points already made. Above all, it won't work.
Sign in to post your reply or Sign up for a free account.
Similar topics
by: powerrun |
last post by:
Help! I have tons of info loaded into an excel spreadsheet that I
need to transfer into an existing database in access. There is a
specific Query I need the information to transfer to. This...
|
by: Bj?rn Keil |
last post by:
Hi,
first of all I have to say I'am new to MS Access, I'm used to database
systems like Oracle or MySQL.
I created a simple database consisting of a single table and a form to
fill in new entrys...
|
by: gpaille |
last post by:
I got a big Access database I'd like to convert to MS SQL Server 2000
and I'm looking for an efficient automated tool to convert data (over
1 400 tables), query, forms and interface.
Does...
|
by: nilsonj |
last post by:
Trying to set up an admin page for an online training registration
page. I am having trouble with a sql statement. Here is the info on the
tables.
I have two tables: classPerson and reglist
...
|
by: Jim |
last post by:
Hi,
I have some basic SQL experience (more programming and EXCEL
experience) and I am having a hard time generating a particular query.
My table is a historical database with columns...
|
by: csgraham74 |
last post by:
Hi Guys,
I was wondering if someone could help me with an access query.
I basicallly have two tables A & B
Im table A there are numerous records with Fields1 & fields 2
I want to use...
|
by: vadarv |
last post by:
Hia!
I'm a total amateur to VBS but need help on a VBS script. This is used in a HMI system from Siemens called WinCC, used for process viewing and control.
What I need to is to write to a table...
|
by: Bosnoval |
last post by:
Access 2003 Databse
ASP.NET 2
Win 2003 Server
Currently I have a search page that only allows a single keyword (person) to be searched at a time. I thought upgrading that option via a multiple...
|
by: Eglute |
last post by:
Hello I want to show the results of MS Access database query in Visual basic. Do you know how to do this? I want to show the results in objects such as label or text box. Please help me. My code is:...
|
by: ng250009 |
last post by:
I am using access database .i want to populate a query which includes i mean which call a function in the query.Finally i want the exact query which populates the variables and aswellas the function...
|
by: taylorcarr |
last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
|
by: Charles Arthur |
last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
|
by: aa123db |
last post by:
Variable and constants
Use var or let for variables and const fror constants.
Var foo ='bar';
Let foo ='bar';const baz ='bar';
Functions
function $name$ ($parameters$) {
}
...
|
by: ryjfgjl |
last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
|
by: emmanuelkatto |
last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud.
Please let me know.
Thanks!
Emmanuel
|
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:
There are some requirements for setting up RAID:
1. The motherboard and BIOS support RAID configuration.
2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
|
by: marktang |
last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
|
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...
| |