Icon View Thread

The following is the text of the current message along with any replies.
Messages 1 to 4 of 4 total
Thread Create multiple records based on a From and To date
Mon, Oct 8 2012 8:02 PMPermanent Link

Alex Vastich

Hi,

I need to create a memory table with separate entries for each day between two specified dates (passed by user), so for example:

1st October  and 5th October are passed, from this I need to create 5 records:

1st October
2nd October
3rd October
4th October
5th October

Is this achievable even if using multiple scripts?  I am using V3.3.

TIA
Al
Mon, Oct 8 2012 8:40 PMPermanent Link

Alex Vastich

Actually if this is impossible, is it possible to create say 1000 entries into a table with one SQL statement?  The idea I have is that if I can create AutoInc table on the fly I can then use autoinc to create unique dates and then remove the records I don't need.

Thanks
Al
Tue, Oct 9 2012 3:52 PMPermanent Link

Tim Young [Elevate Software]

Elevate Software, Inc.

Avatar

Email timyoung@elevatesoft.com

Alex,

<< I need to create a memory table with separate entries for each day
between two specified dates (passed by user), so for example: >>

You're probably going to need to use straight-up Delphi code for this.  It's
very hard, if not impossible, to do without looping/conditional capabilities
in the scripts.

Tim Young
Elevate Software
www.elevatesoft.com
Wed, Oct 10 2012 5:05 AMPermanent Link

John Hay

Alex

> I need to create a memory table with separate entries for each day between two specified dates (passed by user), so
for example:
>
> 1st October  and 5th October are passed, from this I need to create 5 records:
>
> 1st October
> 2nd October
> 3rd October
> 4th October
> 5th October
>
> Is this achievable even if using multiple scripts?  I am using V3.3.

Using a "numbers" table as you suggested is the easiest way.  To create it you could use a cartesian join (v3.3 syntax i
think)

DROP TABLE IF EXISTS memory temp;
CREATE TABLE memory temp (number AUTOINC);
INSERT INTO memory temp VALUES(0);
INSERT INTO memory temp VALUES(0);
INSERT INTO memory temp SELECT number FROM memory temp,memory temp t1,memory temp t2,memory temp t3,memory temp
t4,memory temp t5,memory temp t6,memory temp t7,memory temp t8,memory temp t9,memory temp t10;

This gives you 1026 numbers.

To get the dates something like

SELECT CAST('2012-10-01' AS DATE)+number-1 AS DateField FROM memory temp WHERE number < 6

John

Image