473,748 Members | 2,437 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Finding the Later of 2 Date fields in a query to make a 3rd Datefield

Hi All

I have a query based on a single Table the has the
following fields:
Field 1: BoughtDate
Field 2: SoldDate

Sometimes the SoldDate is earlier than the BoughtDate

What I am trying to do is put the LATER one of
these 2 date fields in a 3 date field called:
LastTradeDate:

Any ideas?

Regards
Bob
Nov 30 '07 #1
4 1470
I think you can just do a quick comparison in an IIF statement to
populate the third date field, like this:

SELECT Table1.BoughtDa te, Table1.SoldDate , IIf([BoughtDate]>[SoldDate],
[BoughtDate],[SoldDate]) AS LastTradeDate
FROM Table1;

Here are my results:

BoughtDate SoldDate LastTradeDate
10/1/2007 11/1/2007 11/1/2007
12/1/2007 11/25/2007 12/1/2007
10/2/2007 10/3/2007 10/3/2007
10/1/2007 9/29/2007 10/1/2007
10/1/2007 8/28/2007 10/1/2007
8/31/2007 9/4/2007 9/4/2007

I hope that helps.
Nov 30 '07 #2
Hi Bob,

I was trying an update with a self join which works in transact sql (for
sql server), but Jet sql (for Access) does not support updates on self
joined tables. Here is what the query looks like (that works -- using
Transact syntax in sql server)

UPDATE tblDates AS t1 INNER JOIN [Select * FROM
(Select RowID, date1 As dateR FROM tblDates WHERE date1 date2
union all select RowID, date2 As dateR From tblDates where date2 >
date1) tA]. AS t2 ON t1.RowID=t2.Row ID SET t1.date3 = t2.dateR;

The error I got was that Jet needs an updatable query. So the
alternative would be to use 2 separate query operations where you update
your 3rd date column first by checking if the boughtDate is greater than
the soldDate. Then run a 2nd update query where the soldDate is
greatedr than the BoughtDate.

Update yourtbl set date3 = dateb
where dateb date2

Update yourtbl set date3 = dates
where dates dateb

Rich

*** Sent via Developersdex http://www.developersdex.com ***
Nov 30 '07 #3
I came up with a better solution

update tblDates set date3 = iif(date1 date2, date1, date2)

Now you can do it in one shot

Rich

*** Sent via Developersdex http://www.developersdex.com ***
Nov 30 '07 #4
Thanks guys that really is a great help
I have learnt somthing new

Regards
Bob
Nov 30 '07 #5

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

5
14895
by: BlackFireNova | last post by:
I need to write a report in which one part shows a count of how many total records fall within the working days (Monday - Friday) inside of a (prompted) given date range, in a particular geographical region. I have written a query which prompts the user for the start and end dates. It also filters for entries which pertain to the particular geographical region. I'm not sure where to go from here.
2
2005
by: Stewart Allen | last post by:
Hi There I have a function that does some calculations depending on the 2 date arguments passed into it: Function GetPeriods(dteStart As Date, dteEnd As Date) As Integer The function has 2 more arguments but they are not causing the problems I'm encountering. The 2 date arguments are used to build a dynamic SQL statement for a
2
1665
by: dude | last post by:
Hi there, I have 2 tables, one with data in it, where each record has a date, this table being table01. I want to apend data to this table, but from Tabl02, but only new data, so essentially append to table01 from table02 where dateField in Table02 is greater than dateField in table01... Hope someone is able to help, I have searched MS access 2000 help thouroughly, but haven't been able to find
10
2982
by: Kenneth | last post by:
I have a Query that consist of a lot of different sales data, and one of the colums are different date. The date goes from 1jan2003 til 31jan2003. in this Query I only want the salesdata for 1jan2003. How do I remove the dates , 2jan2003 til 31jan2003 without removing them from the table, from the Query? (Because I want to use the data for 2jan2003 etc later in other queries) -kenneth
1
3330
by: DL | last post by:
Hi, I have a table with quite a few fields wich saves al kind of activities on has done on one day. Most important to identify a unique record is the date and personID. A person is only allowed to enter his activity data once per date. Now I have to set a condition that will check that a person is not entering his activity data twice for that day. I already have tried a lot in macro's , conditions and VB. Here are some examples:
1
1213
by: Norma | last post by:
I am only posting this again because I did not get any responses the first time I posted it. Excuse me for being redundant here but I can't figure this one out. Original Post: I am trying to make a query pull data from between the dates I enter in the parameter but also look back 'in time' to see where 2 other fields have null values, and only pull data into the query if those 2 fields are null prior to the beginning date of my...
5
1978
by: Helen R Martin | last post by:
I'm struggling once more with the dates in one of my Access projects.. I'd like the date/time fields to be just date fields.. its just confusing the folks using the database, and its making it harder to summarise the data by day in my reports... I think the dates are stored in front of the decimal and the time is stored after the decimal.. so it seems to me if i was storing integers in my fields instead of real numbers I'd have the...
16
11909
by: Mik | last post by:
I apologise if this post seems a little basic, but I am a newbie and have NO access knowledge. I have downloaded the Accounts Ledger from the Microsoft Website. It allows the user to review a report of transactions between a Start & End date. The Tables and forms i believe are UK format "dd/mm/yyyy", However, when I click on "Review Reports" and enter the date as UK "dd/mm/yyyy", it returns nothing.
4
39341
by: perryclisbee via AccessMonster.com | last post by:
I have dates of service for several people that range all over each month. ie: patient had dates of service of: 7/3/2006, 7/24/2006 and 7/25/2006. I need to create a new field via a query that will convert each of the records of these service dates to the first date of that month, with results showing: 7/1/2006, 7/1/2006, 7/1/2006. How would you place an expression on a query that will convert any given date to the first day of the month...
0
8995
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, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
8832
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 effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
9378
jinu1996
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 tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
0
9253
tracyyun
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 protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
1
6798
isladogs
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 presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
6077
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
4879
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
3316
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
2
2791
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.

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.