473,396 Members | 1,683 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,396 software developers and data experts.

Create Weekly and Monthly Flag in database/table

Hi

I have set up a database/tables in Access based on daily timeseries data.
However I would like to create two additional columns in the table as a basis
to pull the data on a weekly and monthly series basis.

Currently, in excel I am using the weekday and EOMONTH functions to create
the flags/indicator in my excel dataset:

(Cells in column A contains daily dates)

Weekly: =IF(WEEKDAY(A12)>WEEKDAY(A13), "WEEKLY", "")
Monthly
=IF(EOMONTH(A13,0)>EOMONTH(A12,0),"Monthly","")

Are these functions are also available in Access? Or is possible to achieve
the result in some other way?

Thanks,

Lucas

--
Message posted via http://www.accessmonster.com

Aug 12 '07 #1
7 4086
"Lucas_london via AccessMonster.com" <u35944@uwewrote in
news:7696fca841644@uwe:
Hi

I have set up a database/tables in Access based on daily
timeseries data. However I would like to create two additional
columns in the table as a basis to pull the data on a weekly
and monthly series basis.

Currently, in excel I am using the weekday and EOMONTH
functions to create the flags/indicator in my excel dataset:

(Cells in column A contains daily dates)

Weekly: =IF(WEEKDAY(A12)>WEEKDAY(A13), "WEEKLY", "")
Monthly
=IF(EOMONTH(A13,0)>EOMONTH(A12,0),"Monthly","")

Are these functions are also available in Access? Or is
possible to achieve the result in some other way?

Thanks,

Lucas
There are similar functions in Access. The IIF() function is
similar to the if IIF stands for Immediate IF, to differentiate
it from the IF in VB.

datediff(period,onedate, seconddate) compares 2 dates. Period is
a text value, eg "d" for days "m" for months, "n" for minutes,
and "yyyy" for years.

See the Visual Basic help on both functions.

However, flags like this do not belong in fields in a table. The
are computed in a query based on the table.

Not knowing how you use the flags, I can't offer specific
instructions on how to write the query you need. Please supply a
few more details.

--
Bob Quintal

PA is y I've altered my email address.

--
Posted via a free Usenet account from http://www.teranews.com

Aug 12 '07 #2
Hi Bob,

In terms of what I'm trying to do. The query below that brings back daily
data from the table "DATA". It is a timeseries table with daily observations,
it is seven fields, and the date field is called field2 and is of the format:
DD/MM/YYY. What I want to do is to have a query to bring back the same output
as below, but instead of daily series, I want it to return weekly data. So I
need a clause in the query that will convert the data to weekly.

So for example for the following sample of dates, I only want to bring back
the row for 29-Jun-07 and 06-Jul-07 only, which are both Fridays.

25-Jun-07
26-Jun-07
27-Jun-07
28-Jun-07
29-Jun-07
02-Jul-07
03-Jul-07
04-Jul-07
05-Jul-07
06-Jul-07

However sometimes this last observation in the week may not always fall on a
Friday, for example during Easter when Friday is a public holiday, the last
observation in the week will be Thursday. That's why I was using that
comparison function in excel so that I could create a flag to identify the
last available observation for any given week. For the majority of cases this
will fall on a Friday but not always.

Hope this makes things clearer.

Thanks,

Lucas
SELECT *
FROM Data
WHERE field1 In ('LLOY','RSA');
Bob Quintal wrote:
>Hi
[quoted text clipped - 18 lines]
>>
Lucas

There are similar functions in Access. The IIF() function is
similar to the if IIF stands for Immediate IF, to differentiate
it from the IF in VB.

datediff(period,onedate, seconddate) compares 2 dates. Period is
a text value, eg "d" for days "m" for months, "n" for minutes,
and "yyyy" for years.

See the Visual Basic help on both functions.

However, flags like this do not belong in fields in a table. The
are computed in a query based on the table.

Not knowing how you use the flags, I can't offer specific
instructions on how to write the query you need. Please supply a
few more details.
--
Message posted via http://www.accessmonster.com

Aug 20 '07 #3
"Lucas_london via AccessMonster.com" <u35944@uwewrote in
news:76f8d0ac114cd@uwe:
Hi Bob,

In terms of what I'm trying to do. The query below that brings
back daily data from the table "DATA". It is a timeseries table
with daily observations, it is seven fields, and the date field is
called field2 and is of the format: DD/MM/YYY. What I want to do
is to have a query to bring back the same output as below, but
instead of daily series, I want it to return weekly data. So I
need a clause in the query that will convert the data to weekly.

So for example for the following sample of dates, I only want to
bring back the row for 29-Jun-07 and 06-Jul-07 only, which are
both Fridays.

25-Jun-07
26-Jun-07
27-Jun-07
28-Jun-07
29-Jun-07
02-Jul-07
03-Jul-07
04-Jul-07
05-Jul-07
06-Jul-07

However sometimes this last observation in the week may not always
fall on a Friday, for example during Easter when Friday is a
public holiday, the last observation in the week will be Thursday.
That's why I was using that comparison function in excel so that I
could create a flag to identify the last available observation for
any given week. For the majority of cases this will fall on a
Friday but not always.

Hope this makes things clearer.

Thanks,

Lucas
SELECT *
FROM Data
WHERE field1 In ('LLOY','RSA');

the weekday(datefield [,optional first day of week)) returns a
number which represents the day of the week, Without the optional
number, fridays are 6.

In the query designer if you put your field2, then surround it wth
the weekday function, you can set the 6 in the criteria row.

Access will add a label, in the form of expr1:, you can change that
to any name you want for the column (within reason)

Now the issue with the missing fridays, one approach is to make a
small table with the holidays that fall on a friday. and join that
table on the dates, changing the join to show all records from your
main table ano the ones from the holidays table where the dates are
equal.

now you can add one to the weekday if the holiday table date is not
null.

so your query becomes something close to

SELECT *
From Data
LEFT Join Holidays
ON data.field2 = Holidays.holiday
WHERE field1 In ('LLOY','RSA');
AND weekday(field2)
+ iif( isnull(Holidays.holiday),0,1)
= 6;
Q
Bob Quintal wrote:
>>Hi
[quoted text clipped - 18 lines]
>>>
Lucas

There are similar functions in Access. The IIF() function is
similar to the if IIF stands for Immediate IF, to differentiate
it from the IF in VB.

datediff(period,onedate, seconddate) compares 2 dates. Period is
a text value, eg "d" for days "m" for months, "n" for minutes,
and "yyyy" for years.

See the Visual Basic help on both functions.

However, flags like this do not belong in fields in a table. The
are computed in a query based on the table.

Not knowing how you use the flags, I can't offer specific
instructions on how to write the query you need. Please supply a
few more details.


--
Bob Quintal

PA is y I've altered my email address.

--
Posted via a free Usenet account from http://www.teranews.com

Aug 20 '07 #4
Bob Quintal wrote:
>Hi Bob,
[quoted text clipped - 38 lines]
>FROM Data
WHERE field1 In ('LLOY','RSA');

the weekday(datefield [,optional first day of week)) returns a
number which represents the day of the week, Without the optional
number, fridays are 6.

In the query designer if you put your field2, then surround it wth
the weekday function, you can set the 6 in the criteria row.

Access will add a label, in the form of expr1:, you can change that
to any name you want for the column (within reason)

Now the issue with the missing fridays, one approach is to make a
small table with the holidays that fall on a friday. and join that
table on the dates, changing the join to show all records from your
main table ano the ones from the holidays table where the dates are
equal.

now you can add one to the weekday if the holiday table date is not
null.

so your query becomes something close to

SELECT *
From Data
LEFT Join Holidays
ON data.field2 = Holidays.holiday
WHERE field1 In ('LLOY','RSA');
AND weekday(field2)
+ iif( isnull(Holidays.holiday),0,1)
= 6;

Q
>>>Hi
[quoted text clipped - 18 lines]
>>>instructions on how to write the query you need. Please supply a
few more details.
------------------------------------------------------------------------------
------
Hi Bob,

Thanks very much for the code and explaining how it works. As per my orginal
posting, I also need to devise a similar query to bring back monthly data -
is there a similar function I could use for this? I've checked the functions
available in Access but could not see one. Again, just likely the weekly
query, for each month I want to bring back the row for the last available
date in that month. I suspect I will need to use a combination of functions
to get the result I need but maybe I'm over complicating things. Any ideas on
the best approach?

Many Thanks,

Lucas

--
Message posted via AccessMonster.com
http://www.accessmonster.com/Uwe/For...ccess/200708/1

Aug 30 '07 #5
"Lucas_london via AccessMonster.com" <u35944@uwewrote in
news:7779dded54462@uwe:
Bob Quintal wrote:
>>Hi Bob,
[quoted text clipped - 38 lines]
>>FROM Data
WHERE field1 In ('LLOY','RSA');

the weekday(datefield [,optional first day of week)) returns a
number which represents the day of the week, Without the optional
number, fridays are 6.

In the query designer if you put your field2, then surround it wth
the weekday function, you can set the 6 in the criteria row.

Access will add a label, in the form of expr1:, you can change
that to any name you want for the column (within reason)

Now the issue with the missing fridays, one approach is to make a
small table with the holidays that fall on a friday. and join that
table on the dates, changing the join to show all records from
your main table ano the ones from the holidays table where the
dates are equal.

now you can add one to the weekday if the holiday table date is
not null.

so your query becomes something close to

SELECT *
From Data
LEFT Join Holidays
ON data.field2 = Holidays.holiday
WHERE field1 In ('LLOY','RSA');
AND weekday(field2)
+ iif( isnull(Holidays.holiday),0,1)
= 6;

Q
>>>>Hi
>
[quoted text clipped - 18 lines]
>>>>instructions on how to write the query you need. Please supply a
few more details.
------------------------------------------------------------------
-
----------- ------
Hi Bob,

Thanks very much for the code and explaining how it works. As per
my orginal posting, I also need to devise a similar query to bring
back monthly data - is there a similar function I could use for
this? I've checked the functions available in Access but could not
see one. Again, just likely the weekly query, for each month I
want to bring back the row for the last available date in that
month. I suspect I will need to use a combination of functions to
get the result I need but maybe I'm over complicating things. Any
ideas on the best approach?

Many Thanks,

Lucas
the dateadd() function will point you in the right direction
if you subtract 1 from the first of any month, you get the last day
of the previous month. The dateserial builds a date from numbers.
The trick is to get the month numbers, from somewhere, perhaps a
small table with the first of each month, or the numbers 1to 12

LastOf Month = dateAdd("d",-1,dateserial(year(now(),month(now(),1)
will return the last day of july since we are in August.


--
Bob Quintal

PA is y I've altered my email address.

--
Posted via a free Usenet account from http://www.teranews.com

Aug 30 '07 #6
Thanks for the suggestion Bob. Not sure if I completely understand it at this
stage.

I am to use this to bring back data in a query as opposed to create a new
feild in the data table right? So in the simplest form I would use it in my
query as something like this:

SELECT *
From Data
WHERE field1 In ('LLOY','RSA');
AND field2 = dateAdd("d",-1,dateserial(year(now(),month(now(),1)

Also, for this to work, do I need to have daily observations for last
calender date in the month? For example for the month of January the last
observation available in my table might be for the 29th of Jan, as opposed to
31st of Jan. Will it still work in this instance, i.e bring back the row for
the 29th of Jan?

Thanks,

Lucas
Bob Quintal wrote:
>>>Hi Bob,
[quoted text clipped - 57 lines]
>>
Lucas

the dateadd() function will point you in the right direction
if you subtract 1 from the first of any month, you get the last day
of the previous month. The dateserial builds a date from numbers.
The trick is to get the month numbers, from somewhere, perhaps a
small table with the first of each month, or the numbers 1to 12

LastOf Month = dateAdd("d",-1,dateserial(year(now(),month(now(),1)
will return the last day of july since we are in August.
--
Message posted via AccessMonster.com
http://www.accessmonster.com/Uwe/For...ccess/200709/1

Sep 4 '07 #7
"Lucas_london via AccessMonster.com" <u35944@uwewrote in
news:77b92aca6a02b@uwe:
Thanks for the suggestion Bob. Not sure if I completely understand
it at this stage.

I am to use this to bring back data in a query as opposed to
create a new feild in the data table right? So in the simplest
form I would use it in my query as something like this:

SELECT *
From Data
WHERE field1 In ('LLOY','RSA');
AND field2 = dateAdd("d",-1,dateserial(year(now(),month(now(),1)
yes, that would bring back the data for the lst day in hte month.
>
Also, for this to work, do I need to have daily observations for
last calender date in the month? For example for the month of
January the last observation available in my table might be for
the 29th of Jan, as opposed to 31st of Jan. Will it still work in
this instance, i.e bring back the row for the 29th of Jan?
This is a different scenario, and actually a little less
complicated.

You can get the highest date in a month using the year() and month()
functions with

Select max(field2) as hidate from mytable group by year(field2),
month(field2);

then join that query on your table on field2 which will return only
the records for the maximum date for that month.

You can then change the join to a subquery:

here's a good tutorial.
http://www.sqlteam.com/article/using...select-records
as is this
http://as400bks.rochester.ibm.com/is...924/index.htm?
info/sqlp/rbafymst141.htm

Thanks,

Lucas
Bob Quintal wrote:
>>>>Hi Bob,
>
[quoted text clipped - 57 lines]
>>>
Lucas

the dateadd() function will point you in the right direction
if you subtract 1 from the first of any month, you get the last
day of the previous month. The dateserial builds a date from
numbers. The trick is to get the month numbers, from somewhere,
perhaps a small table with the first of each month, or the numbers
1to 12

LastOf Month = dateAdd("d",-1,dateserial(year(now(),month(now(),1)
will return the last day of july since we are in August.


--
Bob Quintal

PA is y I've altered my email address.

--
Posted via a free Usenet account from http://www.teranews.com

Sep 4 '07 #8

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

Similar topics

2
by: Jonathan | last post by:
I am looking for a simple way to check if a database table exists. I keep getting advice to use "Try.. Catch" and other error handling methods, but I obviously don't want to have to display an...
1
by: channa_s | last post by:
Hi, I would be very grateful if anyone could help me with the following. I want to create a SIMPLE distributed database. It is as follows: There is a institution which has branches all...
2
by: Vikaspell | last post by:
I have a 2 dimensional table which i want to create in access. this full table i want associated with 1 primasry key or ID how can i do this currently i am entering the table in excell and linking...
4
by: Claudia Fong | last post by:
Hello, I know that we can use C# to connect to a database and using SQL to read data from the tables, update tables, delete record, is there any way to create a table or copy the structure of...
8
by: David | last post by:
Hi, Could someone please xplain how to add a field to an existing SQL table in VB.Net I have added the field in the Server Explorer and it shows up when I reload the program but I cannot...
0
by: ssrirao | last post by:
There is an Excel Spreadsheet containing data, residing in an internet site. It’s very easy to Import data from a local Excel Spreadsheet into SQL Server Database Table using DTS. But in my case...
0
by: sckshreya | last post by:
i am using asp language and ms access database I need to create csv file automatically when i will press one button on my webpage. And this csv file content one table of the database. I also need to...
4
by: qwedster | last post by:
Howdy folks! I am using stored procedure to see if a value exists in database table and return 0 if exists or else -1, in the following SQL queries. However how to check if a value (that is...
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: 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
0
BarryA
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...
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
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
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...
0
Oralloy
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,...
0
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...
0
agi2029
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 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.