Icon View Thread

The following is the text of the current message along with any replies.
Messages 1 to 8 of 8 total
Thread Adding a variable Number of Days to a Date
Thu, Apr 15 2010 7:47 AMPermanent Link

Richard Harding

Wise Nutrition Coaching

I can add 1 day to a DATE column by

     SET NewScheduledStart = ParentScheduledStart + INTERVAL '1' DAY;

Can someone tell me how to add a variable number of days ( say DaysAfter )?

     SET NewScheduledStart = ParentScheduledStart + ??????????? ;

Richard Harding
Thu, Apr 15 2010 8:04 AMPermanent Link

Uli Becker

Richard,

> Can someone tell me how to add a variable number of days ( say DaysAfter )?
>
>       SET NewScheduledStart = ParentScheduledStart + ??????????? ;

Obviously parameters are not allowed with intervals, but you can use this:

'SET NewScheduledStart = ParentScheduledStart + interval ' +
QUOTEDSTR(IntToStr(DaysAfter)) + ' day '

Uli
Thu, Apr 15 2010 8:51 AMPermanent Link

Richard Harding

Wise Nutrition Coaching

Thanks Uli,

What I am trying to do this using cursors -- something like this.

WHILE NOT EOF(TempCursor2) DO
     SET NewScheduledStart =
        ParentScheduledStart + INTERVAL DaysAfterParent DAY;     -- ?????????????????????
     UPDATE TempCursor2 SET
        ScheduledStartDate = NewScheduledStart;
     FETCH NEXT FROM TempCursor2 (DaysAfterParent) INTO DaysAfterParent;
END WHILE;


May be it is not possible using cursors and I need to do as you suggest ---

EXECUTE IMMEDIATE ' UPDATE Activity
SET ScheduledStartDate = ParentScheduledStart + interval ' + QUOTEDSTR(IntToStr(DaysAfter)) + ' day '

Richard Harding
Thu, Apr 15 2010 9:51 AMPermanent Link

Tim Young [Elevate Software]

Elevate Software, Inc.

Avatar

Email timyoung@elevatesoft.com

Richard,

<< What I am trying to do this using cursors -- something like this. >>

How is DaysAfterParent declared ?  Is it an INTEGER or actually declared as
an INTERVAL ?  I have the same question for the DaysAfterParent column that
you're selecting from a table.

After I know the above, I can show you how to do it with a cursor.

--
Tim Young
Elevate Software
www.elevatesoft.com
Thu, Apr 15 2010 4:32 PMPermanent Link

Richard Harding

Wise Nutrition Coaching

Tim,

<< How is DaysAfterParent declared ?  Is it an INTEGER or actually declared as
an INTERVAL ?  I have the same question for the DaysAfterParent column that
you're selecting from a table.>>

The DaysAfterParent column is declared as an INTEGER.
In the PROCEDURE, DaysAfterParent is also declared as an INTEGER ( this can be changed if required).


--
Tim Young
Elevate Software
www.elevatesoft.com
Fri, Apr 16 2010 4:28 AMPermanent Link

John Hay

Richard

> The DaysAfterParent column is declared as an INTEGER.
> In the PROCEDURE, DaysAfterParent is also declared as an INTEGER ( this
can be changed if required).
>

I would guess the following should do it.

SET NewScheduledStart =
        ParentScheduledStart +CAST(DaysAfterParent AS  INTERVAL  DAY);

John

Sat, Apr 17 2010 6:30 AMPermanent Link

Tim Young [Elevate Software]

Elevate Software, Inc.

Avatar

Email timyoung@elevatesoft.com

Richard,

<< The DaysAfterParent column is declared as an INTEGER.
In the PROCEDURE, DaysAfterParent is also declared as an INTEGER ( this can
be changed if required). >>

John's answer is correct.

--
Tim Young
Elevate Software
www.elevatesoft.com
Sun, Apr 18 2010 4:20 PMPermanent Link

Richard Harding

Wise Nutrition Coaching

John - Thank you.

<<SET NewScheduledStart =
        ParentScheduledStart +CAST(DaysAfterParent AS  INTERVAL  DAY);>>

I finally understand how INTERVALS work.

Richard Harding.
Image