BorlandTalk.com Forum Index BorlandTalk.com
Borland discussion newsgroups
 
Archives   FAQFAQ   SearchSearch   MemberlistMemberlist   UsergroupsUsergroups   RegisterRegister 
 ProfileProfile   Log in to check your private messagesLog in to check your private messages   Log inLog in 

SQL guru : Cut Off Day

 
Post new topic   Reply to topic    BorlandTalk.com Forum Index -> Delphi Databases (Desktop)
View previous topic :: View next topic  
Author Message
Uncle Potato
Guest





PostPosted: Tue Nov 09, 2004 8:46 am    Post subject: SQL guru : Cut Off Day Reply with quote



I have a date field (TrDate) in an dbase table, I have been using
extract to implement the month of transaction, as in

(Extract(Year from TrDate)*100+Extract(Month from TrDate)) as YM

So in the report, I can simply use YM as a grouping expression.

Now my client want to add a cutoff, say the 4th day as the cut off,
(i.e. 1st, 2nd, 3rd day are count as previous month's entry) how do
you do it with SQL ??

Now I am saving the temp table, loop through with delphi statement to
fill in the desired YM field, but it is just taking too long.

Any suggestion ??
Back to top
Bojidar Alexandrov
Guest





PostPosted: Tue Nov 09, 2004 10:51 am    Post subject: Re: SQL guru : Cut Off Day Reply with quote



"Uncle Potato" <Potato (AT) aelhk (DOT) com> wrote

Quote:
I have a date field (TrDate) in an dbase table, I have been using
extract to implement the month of transaction, as in

(Extract(Year from TrDate)*100+Extract(Month from TrDate)) as YM

Does the year have 100 months?


Quote:
So in the report, I can simply use YM as a grouping expression.

Now my client want to add a cutoff, say the 4th day as the cut off,
(i.e. 1st, 2nd, 3rd day are count as previous month's entry) how do
you do it with SQL ??


If you substract 1, 2 or 3 days from the date and then use Extract it will
work.


Bojidar Alexandrov



Back to top
Uncle Potato
Guest





PostPosted: Wed Nov 10, 2004 2:34 am    Post subject: Re: SQL guru : Cut Off Day Reply with quote



Quote:
(Extract(Year from TrDate)*100+Extract(Month from TrDate)) as YM

Does the year have 100 months?

Does it matter??
As long as they can group together, it works fine,
i.e. 200411, 200412, 200501, ...
YM field can also be a label directly and is human friendly....

Using *12 instead of *100, you will get a number counting number of
months from year 0. It mathematically means something, but there is
no advantage at all.

Quote:
Now my client want to add a cutoff, say the 4th day as the cut off,
(i.e. 1st, 2nd, 3rd day are count as previous month's entry) how do
you do it with SQL ??

If you substract 1, 2 or 3 days from the date and then use Extract it will
work.

Good idea... But unfortunately date field isn't the same as

TdateTIme, SQL don't allow me to do simple math to do
subtraction........

Back to top
Uncle Potato
Guest





PostPosted: Wed Nov 10, 2004 9:04 am    Post subject: Re: SQL guru : Cut Off Day Reply with quote

Quote:

Now my client want to add a cutoff, say the 4th day as the cut off,
(i.e. 1st, 2nd, 3rd day are count as previous month's entry) how do
you do it with SQL ??

If you substract 1, 2 or 3 days from the date and then use Extract it will
work.


I figure out the maths like this now:
work out the grouping field YM as
Year * 1200 + Month * 100 + Day - 1 - CutOff
the YM field has the last two digits as the DAY, hundreds become
number of months starting from year 0.

To group the month, I do a Int(YM / 100)
The month label would be
IntToStr( Int(YM/100/12)) +'/'+ IntToStr( (Int(YM/100) mod 12))



Back to top
John Herbster
Guest





PostPosted: Wed Nov 10, 2004 11:53 am    Post subject: Re: SQL guru : Cut Off Day Reply with quote


"Uncle Potato" <Potato (AT) aelhk (DOT) com> wrote

Quote:
Does it matter??
As long as they can group together, it works fine,
i.e. 200411, 200412, 200501, ...
YM field can also be a label directly and is human friendly....
Using *12 instead of *100, you will get a number counting
number of months from year 0. It mathematically means
something, but there is no advantage at all.

No advantage? What about for date arithmetic?

Uncle, If you are not familiar with the GetText and SetText
event methods of the dataset field, I suggest that you may
want to look at them, they allow you to easily transform
dates between machine and human readable forms.
Regards, JohnH

Back to top
Bojidar Alexandrov
Guest





PostPosted: Thu Nov 11, 2004 7:29 am    Post subject: Re: SQL guru : Cut Off Day Reply with quote

Quote:
Now my client want to add a cutoff, say the 4th day as the cut off,
(i.e. 1st, 2nd, 3rd day are count as previous month's entry) how do
you do it with SQL ??

If you substract 1, 2 or 3 days from the date and then use Extract it
will
work.

Good idea... But unfortunately date field isn't the same as
TdateTIme, SQL don't allow me to do simple math to do
subtraction........

As addition to John Herbster,

You did'nt mention what database you use, but in Interbase you can timestamp
datatype is similar to Delphi one and substracting a day is done with
substracting 1 from the date directly.
Other rdbms-es have functions to add/substract to date

Bojidar Alexandrov



Back to top
Display posts from previous:   
Post new topic   Reply to topic    BorlandTalk.com Forum Index -> Delphi Databases (Desktop) All times are GMT
Page 1 of 1

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum


Powered by phpBB © 2001, 2006 phpBB Group
SEO toolkit © 2004-2006 webmedic.