 |
BorlandTalk.com Borland discussion newsgroups
|
| View previous topic :: View next topic |
| Author |
Message |
Tim Guest
|
Posted: Mon Oct 16, 2006 8:11 am Post subject: MySQL CAST function |
|
|
I want to create a select statement which includes a calculated field along
the lines of:
select
d.*,
(adate - d.days_before_departure)
from departures d
which might be used to give a list of people to send documents a certain
number of days before they fly.
I have tried cast('2007-01-01' as date) - d.days_before_departure, but it
only returns the year part minus the d.days_before_departure value.
Also, I want the result field to have a specific name, such as send_date.
Normally, I would use (adate - d.days_before_departure) as send_date, but
using the cast method above, it gives an error.
Can anyone tell me how to make this work?
Thanks. |
|
| Back to top |
|
 |
Guillem Guest
|
Posted: Mon Oct 16, 2006 2:13 pm Post subject: Re: MySQL CAST function |
|
|
Tim wrote:
| Quote: | I want to create a select statement which includes a calculated field
along the lines of:
select
d.*,
(adate - d.days_before_departure)
from departures d
which might be used to give a list of people to send documents a
certain number of days before they fly.
I have tried cast('2007-01-01' as date) - d.days_before_departure,
but it only returns the year part minus the d.days_before_departure
value.
Also, I want the result field to have a specific name, such as
send_date. Normally, I would use (adate - d.days_before_departure)
as send_date, but using the cast method above, it gives an error.
Can anyone tell me how to make this work?
Thanks.
|
Try this (untested)
select
d.*,
DATE_SUB(adate, INTERVAL d.days_before_departure DAY)
from departures d
--
Best regards :)
Guillem Vicens Meier
Dep. Informatica Green Service S.A.
www.clubgreenoasis.com
--
Contribute to the Indy Docs project: http://docs.indyproject.org
--
In order to contact me remove the -nospam |
|
| Back to top |
|
 |
Tim Guest
|
Posted: Tue Oct 17, 2006 4:26 pm Post subject: Re: MySQL CAST function |
|
|
Thanks Guillem,
I was not aware of the date_sub function, but have looked it up in the
documentation. Your example works fine anyway.
Tim
"Guillem" <guillemvicens-nospam (AT) clubgreenoasis (DOT) com> wrote in message
news:45334d33$1 (AT) newsgroups (DOT) borland.com...
| Quote: |
Try this (untested)
select
d.*,
DATE_SUB(adate, INTERVAL d.days_before_departure DAY)
from departures d
--
Best regards :)
Guillem Vicens Meier
Dep. Informatica Green Service S.A.
www.clubgreenoasis.com
--
Contribute to the Indy Docs project: http://docs.indyproject.org
--
In order to contact me remove the -nospam
|
|
|
| Back to top |
|
 |
|
|
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
|
|