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 

MySQL CAST function

 
Post new topic   Reply to topic    BorlandTalk.com Forum Index -> Delphi Databases (SQL Servers)
View previous topic :: View next topic  
Author Message
Tim
Guest





PostPosted: Mon Oct 16, 2006 8:11 am    Post subject: MySQL CAST function Reply with 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.
Back to top
Guillem
Guest





PostPosted: Mon Oct 16, 2006 2:13 pm    Post subject: Re: MySQL CAST function Reply with quote



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





PostPosted: Tue Oct 17, 2006 4:26 pm    Post subject: Re: MySQL CAST function Reply with quote



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
Display posts from previous:   
Post new topic   Reply to topic    BorlandTalk.com Forum Index -> Delphi Databases (SQL Servers) 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.