Solved

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

Posted on 2009-04-06
1
483 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
1 Comment
 
LVL 18

Accepted Solution

by:
mirtheil earned 250 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

On Demand Webinar - Networking for the Cloud Era

This webinar discusses:
-Common barriers companies experience when moving to the cloud
-How SD-WAN changes the way we look at networks
-Best practices customers should employ moving forward with cloud migration
-What happens behind the scenes of SteelConnect’s one-click button

Question has a verified solution.

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

Recently, Microsoft released a best-practice guide for securing Active Directory. It's a whopping 300+ pages long. Those of us tasked with securing our company’s databases and systems would, ideally, have time to devote to learning the ins and outs…
In this series, we will discuss common questions received as a database Solutions Engineer at Percona. In this role, we speak with a wide array of MySQL and MongoDB users responsible for both extremely large and complex environments to smaller singl…
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…
This is a high-level webinar that covers the history of enterprise open source database use. It addresses both the advantages companies see in using open source database technologies, as well as the fears and reservations they might have. In this…

696 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