473,396 Members | 1,814 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.

Month question

vp
Hi all,

I have a table which has claims data..On any particular day I will
have to extract all the record from the previous month.(considering
leap years and months like Feb 28/29 days)

can you please help me...

thanks
vijay

Feb 2 '06 #1
12 13981
WHERE MONTH(date_column) = MONTH(CURRNT_DATE - 1 MONTH)
AND YEAR(date_column) = YEAR(CURRNT_DATE - 1 MONTH)

Feb 2 '06 #2
vp
Hi,

I have to extract records for the previous month from 1st of the
previous month to the last day of the previous month..

thanks..

Feb 2 '06 #3
It can be done without using a FUNCTION on the COLUMN.

WHERE date_column BETWEEN
CURRENT DATE - (DAY(CURRENT DATE) - 1) DAYS - 1 MONTH
AND CURRENT DATE - DAY(CURRENT DATE) DAYS

B.

Feb 2 '06 #4
I remembered that you already showed this smart way.

UDB date query
http://groups.google.com/group/comp....fe17ced3?hl=en

Feb 2 '06 #5
In that case, a TIMESTAMP was used, so a conversion on the COLUMN was
needed, if done in this method.

B.

Feb 2 '06 #6
vp
Hi,

these below cases fail for to get 1st and last day of the month...

db2 "select (date('2006-03-03') - (DAY(CURRENT DATE) - 1) DAYS - 1
MONTH) from sysibm.sysdummy1"

db2 "select (date('2006-04-03') - DAY(CURRENT DATE) DAYS ) from
sysibm.sysdummy1"

only if todays day('03') equals CURRENT day than only the query is
working..

please let me know...

Feb 2 '06 #7
If you are not using CURRENT DATE, you must replace both instances:

db2 "select (date('2006-03-03') - (DAY(date('2006-03-03')) - 1) DAYS
- 1 MONTH) from sysibm.sysdummy1"
db2 "select (date('2006-04-03') - DAY(date('2006-04-03')) DAYS ) from
sysibm.sysdummy1"

B.

Feb 2 '06 #8
Easiest way to do this
is with a range table. They usually look like this:
CREATE TABLE ReportRanges
(range_name CHAR(15) NOT NULL PRIMARY KEY,
start_date DATETIME NOT NULL,
end_date DATETIME NOT NULL,
CHECK (start_date < end_date));

INSERT INTO ReportRanges
VALUES ('2006-01 Report', '2005-01-01', '2006-02-28 23:59:59.9999');
etc.

SELECT R.range_name, <<you gave no specs!!>> ...
FROM Ploof AS P, ReportRanges AS
WHERE P.ploof_date BETWEEN R.start_date AND COLESCE (R.end_date,
CURRENT_TIMESTAMP)
GROUP BY P.program_name;

The reasons for using a table

1) Portability. Temporal functions vary quite a bit from product.

2) Standards conformance.

3) Control at the day by say level -- exclude holidays, cut off before
midnight, etc.

4) The Calendar table is a more general tool for other temporal
problems. For a small extra effort now, he can solve a lot of problems
in the future.

Feb 3 '06 #9
I am glad you took my advice and added a primary key to the table and
made the ranges not locale specific.

Now, if we can only get you to...

a) name columns on the INSERT
b) use ansi 92 join syntax instead of that confusing comma stuff of the
previous standard.

Don't forget to mention the dramatic overhead posed in maintaining a
calendar table across multiple countries.
--CELKO-- wrote:
Easiest way to do this
is with a range table. They usually look like this:
CREATE TABLE ReportRanges
(range_name CHAR(15) NOT NULL PRIMARY KEY,
start_date DATETIME NOT NULL,
end_date DATETIME NOT NULL,
CHECK (start_date < end_date));

INSERT INTO ReportRanges
VALUES ('2006-01 Report', '2005-01-01', '2006-02-28 23:59:59.9999');
etc.

SELECT R.range_name, <<you gave no specs!!>> ...
FROM Ploof AS P, ReportRanges AS
WHERE P.ploof_date BETWEEN R.start_date AND COLESCE (R.end_date,
CURRENT_TIMESTAMP)
GROUP BY P.program_name;

The reasons for using a table

1) Portability. Temporal functions vary quite a bit from product.

2) Standards conformance.

3) Control at the day by say level -- exclude holidays, cut off before
midnight, etc.

4) The Calendar table is a more general tool for other temporal
problems. For a small extra effort now, he can solve a lot of problems
in the future.


Feb 3 '06 #10
>> Don't forget to mention the dramatic overhead posed in maintaining a calendar table across multiple countries. <<

a) name columns on the INSERT

Okay, my bad for short code in a newsgroup. Gee, nobody else does
that, do they?

b) use ansi 92 join syntax instead of that confusing comma stuff of the
previous standard.

This is still valid, Standard SQL. Why do you think that the verbose
infixed syntax is preferred? for INNER JOINs?

Unh? I use UTC and the TIMEZONE stuff in SQL-92 to convert to local
times. I have to "fake it" with VIEWs in older products, but that is
all.

Feb 3 '06 #11
>>> Okay, my bad for short code in a newsgroup. Gee, nobody else does
that, do they?

Not anybody with professional experience and training, and if you are
doing it lazy hand then undoubtedly you'll be writing it in your
production systems.

I'll have to remember to mention this when you next bash somebody for
using terms incorrectly - fields/columns records/rows; its a dam site
more serious not specifying what columns you are inserting into on the
INSERT - you will get data corruption!
This is still valid, Standard SQL. Why do you think that the verbose infixed syntax is preferred? for INNER JOINs?

Using INNER and CROSS JOIN keywords gives you distinction in the
statement, you can clearly see the join clause, the select clause and
the where clause, you don't have to work out whats a join and whats a
filter in the where clause.

select ...
from yourtable as t
inner join yourothertable as b on b.yourpk = t.yourpk
where t.colsearch = 'asdad'

And not written as I've seen you post it elsewhere to booster your
argument...

select ...
from yourtable as t
inner join
yourothertable as b
on b.yourpk = t.yourpk
where t.colsearch = 'asdad'

Which quite frankly is unreadable.

Don't rely on the comma syntax it might be depreciated in a release of
the standard in the future, things do get depreciated in the standard!
Unh? I use UTC and the TIMEZONE stuff in SQL-92 to convert to local

times. I have to "fake it" with VIEWs in older products, but that is
all

Yes, but you are not using the correct standard formatting though. Most
modern, certainly the major rdbms take the format in the correct
standard form - so use it!

Feb 4 '06 #12
On 2 Feb 2006 09:08:30 -0800, "Tonkuma" <to*****@jp.ibm.com> wrote:
I remembered that you already showed this smart way.

UDB date query
http://groups.google.com/group/comp....fe17ced3?hl=en

Feb 5 '06 #13

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

Similar topics

5
by: Ken Fine | last post by:
I want my application to maintain a directory tree based on months and years, e.g.: 2004 January file file file February file
6
by: Mark Anthony | last post by:
ok so first i will give write the question out, my code, the db structure, then what is going wrong. Write a report to return the top store in terms of Sales Dollars for each month sales have...
1
by: Ben | last post by:
Hi I am currently building a database in Access 97 and have a (quite easy) question. I want to produce a query / report that will bring out all the people in the database that have a birthday...
34
by: prosoft | last post by:
When I use Dim myDTFI As DateTimeFormatInfo = New CultureInfo("he-IL", True).DateTimeFormat Dim strhmon1 As String = (myDTFI.GetMonthName(hmon1)) MsgBox(strhmon1) I get the local name of the...
6
by: Burghew | last post by:
Hello, I generate invoices for my customers evry month. I want to keep a form which will allow the user to select the Month and Year through a combo and thus generate reports based on the month...
18
by: PC Datasheet | last post by:
An Access user saw my name in a newsgroup and sent me a request for help on a project. As part of the project, a list of the dates in a month was needed. For anyone needing a list of dates in a...
22
by: Stan | last post by:
I am working with Access 2003 on a computer running XP. I am new at using Access. I have a Db with a date field stored as mm/dd/yyyy. I need a Query that will prompt for the month, ie. 6 for...
3
by: JC21 | last post by:
Hello all, I have a question on MS calendar. On one of my forms in my DB I have the MS calendar. My question is how do I set the calendar so that the current month is always displayed. Currently...
5
by: wugon.net | last post by:
question: db2 LUW V8 UNION ALL with table function month() have bad query performance Env: db2 LUW V8 + FP14 Problem : We have history data from 2005/01/01 ~ 2007/05/xx in single big...
5
by: Seb | last post by:
I want to count activity in a given month. I'm trying to do so with the linq code below however it reports: Error 1 'a' is inaccessible due to its protection level var ActivityByMonths = from a...
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: 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
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...
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.