Solved

I need to fill a column in a Pervasive SQL table with sequential numbers

Posted on 2009-04-06
1
425 Views
Last Modified: 2012-05-06
I have created a new empty table with only one column, I need to fill this column with sequential numbers from 0 to 2000. I could do it manual but the time it would take along with possibility of errors makes this method not first choose. There must be a script I could use in the Pervasive SQL Control Center to do this simple task, but I have been unable to come up with one.  

Thanks.
0
Comment
Question by:dental99
1 Comment
 
LVL 18

Accepted Solution

by:
mirtheil earned 250 total points
Comment Utility
There's not a way to do it with one query but you could write a Stored Procedure.  Something like:
create procedure popTable(in :NumRecords INT);
begin
DECLARE :i INTEGER;
SET :i = 0;
WHILE :i <= :NumRecords DO
INSERT INTO test1 (f1) values (:i);
SET :i = :i + 1;
END WHILE;
end;

or (creating the table in the procedure):
create procedure popTable(in :NumRecords INT);
begin
exec ('CREATE TABLE test1 (f1 integer);');
DECLARE :i INTEGER;
SET :i = 0;
WHILE :i <= :NumRecords DO
INSERT INTO test1 (f1) values (:i);
SET :i = :i + 1;
END WHILE;
end;

and then executing the Stored Procedure:

CALL popTest(2000);
0

Featured Post

IT, Stop Being Called Into Every Meeting

Highfive is so simple that setting up every meeting room takes just minutes and every employee will be able to start or join a call from any room with ease. Never be called into a meeting just to get it started again. This is how video conferencing should work!

Join & Write a Comment

Database tuning – How to start and what to tune. This question is frequently asked by many people, both online and offline. There is no hard and fast rule-of-thumb for performance tuning, however, before beginning the tuning process one should a…
Entity Framework is a powerful tool to help you interact with the DataBase but still doesn't help much when we have a Stored Procedure that returns more than one resultset. The solution takes some of out-of-the-box thinking; read on!
Video by: Steve
Using examples as well as descriptions, step through each of the common simple join types, explaining differences in syntax, differences in expected outputs and showing how the queries run along with the actual outputs based upon a simple set of dem…
Polish reports in Access so they look terrific. Take yourself to another level. Equations, Back Color, Alternate Back Color. Write easy VBA Code. Tighten space to use less pages. Launch report from a menu, considering criteria only when it is filled…

763 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

6 Experts available now in Live!

Get 1:1 Help Now