?
Solved

generating 8-digit sequence

Posted on 2000-05-02
4
Medium Priority
?
552 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
[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
  • 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

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

Recently I was talking with Tim Sharp, one of my colleagues from our Technical Account Manager team about MongoDB’s scalability. While doing some quick training with some of the Percona team, Tim brought something to my attention...
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 …
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…
In this video, Percona Solution Engineer Rick Golba discuss how (and why) you implement high availability in a database environment. To discuss how Percona Consulting can help with your design and architecture needs for your database and infrastr…

752 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