[Last Call] Learn how to a build a cloud-first strategyRegister Now

x
?
Solved

generating 8-digit sequence

Posted on 2000-05-02
4
Medium Priority
?
570 Views
Last Modified: 2011-10-03
how do i generate a full 8-digit sequence number using sql? for example, i would like to generate

00000001
00000002
00000003

instead of

1
2
3

i am using the postgresql database.
0
Comment
Question by:wsanchez
  • 2
4 Comments
 

Expert Comment

by:lgmm
ID: 2774338
try with cast

select cast(00000001 as string)

if you are using direct numbers like  select 00000001 or something like this
try (select '00000001' as string) as number

are you walter sanchez?
0
 

Author Comment

by:wsanchez
ID: 2776366
thanks for the suggestion, but is it possible to generate a sequence with all the digits from the very beginning? for example:

CREATE SEQUENCE seq_code;

CREATE TABLE table1 (
      SequenceNum      integer default nextval('SequenceNum'),
      Field1            varchar(8)
);

for the 'SequenceNum' field under table1, i would like the sequence generated with all of the 8 digits.

thanks.

lgmm, nope, i'm not walter.
0
 

Expert Comment

by:lgmm
ID: 2777396
look for a mask, this kind of problems is common to solve with mask or something like this, some structure or picture command
0
 

Accepted Solution

by:
csabay earned 150 total points
ID: 2788778
Hi, WSanchez,

your solution is:

select right(str(100000000 + SequenceNum,9),8)

Regards

Charles
0

Featured Post

Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

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

This article shows how to get a list of available printers for display in a drop-down list, and then to use the selected printer to print an Access report or a Word document filled with Access data, using different syntax as needed for working with …
In this blog post, we’ll look at how using thread_statistics can cause high memory usage.
In this video, Percona Solutions Engineer Barrett Chambers discusses some of the basic syntax differences between MySQL and MongoDB. To learn more check out our webinar on MongoDB administration for MySQL DBA: https://www.percona.com/resources/we…
With just a little bit of  SQL and VBA, many doors open to cool things like synchronize a list box to display data relevant to other information on a form.  If you have never written code or looked at an SQL statement before, no problem! ...  give i…
Suggested Courses

834 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