
Few questions from a DB2 newbie (date functions in SQL and good documentation)
Quote:
> > Hi everyone!
> > I'm a long time database programmer connecting to and
> > executing DB2 specific SQL statements for the first time
> > Thanks Alot!
> > - alex
> Assume we have a column/parameter D:
> 1. last day of month
> D + 1 month - day(D + 1 month) days
> 2. last day of last month
> D - day(D) days
> 3. nearest friday (Friday is today, else next nearest/next Friday)
> D + mod(13-dayofweek(D),7) days
> 4. nearest last friday (Friday is today, else next nearest last/prev Friday)
> D - mod(1+dayofweek(D),7) days
> So,
> 5. the date of the last friday of last month
> Put [2] in p[4].
> Zur Aougav
WOW ... I'm truly impressed ... I had given up and used
visual basic to calculate the values listed in your
formulas above
then executed a replace on the text of the SQL statement
before running it
but this would work too (and it's all SQL)
BTW, In my reading of both the SQL cookbook and the
IBM documentation, I was unable to find the specific
commands involved in doing transactions and calculations
in DB2-SQL
In MS-SQL server I'd been able to something
along the lines of the following (and forgive me,
my syntax will be disgusting here, i'm rusty in
T-SQL):
BEGIN
END
I htink there were some other things you'd have to
do like return the SELECT statement ... and quite
honestly, I'm not even sure if I was ever able to
do this type of calculation on the fly or if it was
just in the context of writing triggers and functions
it dosen't change the fact that I'd like to do it in DB2
though :D! Does DB2 have the ability to do calculations
before executing the SQL?
Because of my level of access, I cannot create a user
defined function on the server ... but If it's possible
to write the whole thing in some kickass-SQL who need it ?
Thanks!