473,386 Members | 1,644 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,386 software developers and data experts.

Access Database Query Help

Catalyst159
111 100+
I am trying to correct the following query:

Expand|Select|Wrap|Line Numbers
  1. UPDATE marriages SET marriages.[Date of Marriage] = Format(CDate([Date of Marriage]),'m/d/yyyy')
  2.  
  3. 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.
Nov 16 '11 #1
20 1855
TheSmileyCoder
2,322 Expert Mod 2GB
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.
Nov 16 '11 #2
ADezii
8,834 Expert 8TB
How about Updating only if a valid Date exists, as in:
Expand|Select|Wrap|Line Numbers
  1. WHERE IsDate(marriages.[Date of Marriage])
Nov 16 '11 #3
Catalyst159
111 100+
You are correct. It is a text field.
Nov 16 '11 #4
Catalyst159
111 100+
But if a valid date exists then what would it actually be updating?
Nov 16 '11 #5
Catalyst159
111 100+
This would update only format then ?
Nov 16 '11 #6
TheSmileyCoder
2,322 Expert Mod 2GB
I believe so.
But always take backup before you run a big update query if your not sure on the results :)
Nov 16 '11 #7
Catalyst159
111 100+
The problem I am having now is when I run the following query:

Expand|Select|Wrap|Line Numbers
  1. UPDATE marriages_cpy SET marriages_cpy.[Date of Marriage] = Format(CDate([Date of Marriage]),'m/d/yyyy')
  2. WHERE marriages_cpy.[Date of Marriage] <> 'VOID' OR IsDate([Date of Marriage]);
  3.  

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.
Nov 16 '11 #8
TheSmileyCoder
2,322 Expert Mod 2GB
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.
Expand|Select|Wrap|Line Numbers
  1. UPDATE marriages_cpy SET marriages_cpy.[Date of Marriage] = Format(CDate([Date of Marriage]),'m/d/yyyy') 
  2. WHERE IsDate([Date of Marriage]);
Nov 16 '11 #9
Catalyst159
111 100+
So what would happen to a record that has a value of 1980 then? It would remain 1980 right ?
Nov 16 '11 #10
TheSmileyCoder
2,322 Expert Mod 2GB
Yes 1980 would remain 1980. The query will only work on valid dates.
Nov 16 '11 #11
Catalyst159
111 100+
Yes you are right. I just tested it. Looks good. Any ideas as to why it was deleting the value before?
Nov 16 '11 #12
TheSmileyCoder
2,322 Expert Mod 2GB
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:
Expand|Select|Wrap|Line Numbers
  1. ? 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.
Nov 16 '11 #13
Catalyst159
111 100+
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.
Nov 16 '11 #14
TheSmileyCoder
2,322 Expert Mod 2GB
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.
Nov 16 '11 #15
Catalyst159
111 100+
I have a better idea of what is happening now. Thanks for the explanation and the help.

Catalyst
Nov 16 '11 #16
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
Expand|Select|Wrap|Line Numbers
  1. ?CDate(-1),CDate(-657434)
  2. 29/12/1899    01/01/100
Your update query could be simply (fundamentally similar to other suggestions but slightly shorter) :
Expand|Select|Wrap|Line Numbers
  1. UPDATE [Marriages]
  2. SET    [Date of Marriage] = Format(CDate([Date of Marriage]),'m/d/yyyy')
  3. 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.
Nov 17 '11 #17
Catalyst159
111 100+
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.
Nov 17 '11 #18
Rabbit
12,516 Expert Mod 8TB
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.
Nov 17 '11 #19
Expand|Select|Wrap|Line Numbers
  1. UPDATE marriages SET marriages.[Date of Marriage] = Format(CDate([Date of Marriage]),'m/d/yyyy')
  2.  
  3. WHERE marriages.[Date of Marriage] Is Not Null OR marriages.[Date of Marriage]Or marriages.[CDate] <> 'VOID';
Nov 17 '11 #20
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.
Nov 18 '11 #21

Sign in to post your reply or Sign up for a free account.

Similar topics

5
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...
1
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...
1
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...
1
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 ...
4
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...
1
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...
1
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...
23
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...
1
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:...
1
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...
0
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,...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
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$) { } ...
0
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...
0
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
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
0
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...
0
marktang
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,...
0
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 using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.