Icon View Thread

The following is the text of the current message along with any replies.
Messages 1 to 10 of 32 total
Thread Syntax for date calculation
Sat, May 26 2012 4:04 AMPermanent Link

Hershcu Sorin

Hello

I cand find the right syntax for the statement that return the NewDateField

SELECT DateField + a integer of months AS NewDateField

Thanks
Sorin

Sat, May 26 2012 8:20 AMPermanent Link

Uli Becker

Sorin,

> I cand find the right syntax for the statement that return the NewDateField
>
> SELECT DateField + a integer of months AS NewDateField

You have to work with intervals. Not the quotes!

select DateField + interval '1' month as NewDateField from ...

Uli
Sat, May 26 2012 8:21 AMPermanent Link

Uli Becker

correction:

I meant "note the quotes" not "not the quotes".

Tiny typo, big difference. Smile

Uli
Sat, May 26 2012 8:42 AMPermanent Link

Roy Lambert

NLH Associates

Team Elevate Team Elevate

Uli


Nice typo - I think I prefer it to the correct version Smiley

Also note that the interval can't be specified as a parameter. If you want to change it you have to change the sql.

Roy Lambert [Team Elevate]
Sat, May 26 2012 9:50 AMPermanent Link

Uli Becker

Roy,

> Nice typo - I think I prefer it to the correct versionSmiley

Smile

> Also note that the interval can't be specified as a parameter. If you want to change it you have to change the sql.

In such cases I use something like this:

select Datefield + interval ''' + Cast(MyIntValue as Varchar) + '''
month from MyTable';

Uli
Sat, May 26 2012 10:02 AMPermanent Link

Hershcu Sorin

Thanks

That mean that if I want do something like

select DateField, DateField + interval NumberField month as NewDateField...

I can't?

Sorin


> Also note that the interval can't be specified as a parameter. If you want
> to change it you have to change the sql.
>
> Roy Lambert [Team Elevate]
>

Sat, May 26 2012 10:17 AMPermanent Link

Hershcu Sorin

Thanks Uli

I try

select DateField + interval ''' +cast(intField as varchar) + ''' month as
NewDateField...

but it raise error #700 before interval

Sorin

Sun, May 27 2012 2:39 AMPermanent Link

Uli Becker

This script with a table called "Kalender" and a Date Column called
"Datum" does work:

SCRIPT
BEGIN

   DECLARE Result CURSOR WITH RETURN FOR Stmt;
   DECLARE Delta INTEGER DEFAULT 2;

   PREPARE Stmt FROM
      'select Datum + interval ''' + cast(Delta as varchar) + ''' month as
       NewDateField from Kalender';
   OPEN Result;

END

Uli
Mon, May 28 2012 5:55 AMPermanent Link

Hershcu Sorin

Thanks Uli

I need the state in a query not in a script.

edbQuery.sql.text :=  'select Datum + interval ''' + cast(Delta as varchar)
+ ''' month as...

Does it make any difference?


> SCRIPT
> BEGIN
>
>    DECLARE Result CURSOR WITH RETURN FOR Stmt;
>    DECLARE Delta INTEGER DEFAULT 2;
>
>    PREPARE Stmt FROM
>       'select Datum + interval ''' + cast(Delta as varchar) + ''' month as
>        NewDateField from Kalender';
>    OPEN Result;
>
> END
>
> Uli
>

Mon, May 28 2012 6:27 AMPermanent Link

Uli Becker

Sorin,

> I need the state in a query not in a script.
>
> edbQuery.sql.text :=  'select Datum + interval ''' + cast(Delta as varchar)
> + ''' month as...
>
> Does it make any difference?

It's the same: just compose the statement like this:

with MyQuery do
begin
  sql.add('select Datum + interval ''' + IntToStr(MyIntValue) + '''
month as NewField from Kalender');
  open;
end;

Uli
Page 1 of 4Next Page »
Jump to Page:  1 2 3 4
Image