[Okta Webinar] Learn how to a build a cloud-first strategyRegister Now

x
?
Solved

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

Posted on 2009-04-06
1
Medium Priority
?
499 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 750 total points
ID: 24081440
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

Microsoft Certification Exam 74-409

Veeam® is happy to provide the Microsoft community with a study guide prepared by MVP and MCT, Orin Thomas. This guide will take you through each of the exam objectives, helping you to prepare for and pass the examination.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

This post looks at MongoDB and MySQL, and covers high-level MongoDB strengths, weaknesses, features, and uses from the perspective of an SQL user.
Backups and Disaster RecoveryIn this post, we’ll look at strategies for backups and disaster recovery.
In this video, Percona Solution Engineer Dimitri Vanoverbeke discusses why you want to use at least three nodes in a database cluster. To discuss how Percona Consulting can help with your design and architecture needs for your database and infras…
In this video, Percona Director of Solution Engineering Jon Tobin discusses the function and features of Percona Server for MongoDB. How Percona can help Percona can help you determine if Percona Server for MongoDB is the right solution for …
Suggested Courses

872 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