Solved

generating 8-digit sequence

Posted on 2000-05-02
4
518 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 50 total points
ID: 2788778
Hi, WSanchez,

your solution is:

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

Regards

Charles
0

Featured Post

VMware Disaster Recovery and Data Protection

In this expert guide, you’ll learn about the components of a Modern Data Center. You will use cases for the value-added capabilities of Veeam®, including combining backup and replication for VMware disaster recovery and using replication for data center migration.

Question has a verified solution.

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

Entering a date in Microsoft Access can be tricky. A typo can cause month and day to be shuffled, entering the day only causes an error, as does entering, say, day 31 in June. This article shows how an inputmask supported by code can help the user a…
Using SQL Scripts we can save all the SQL queries as files that we use very frequently on our database later point of time. This is one of the feature present under SQL Workshop in Oracle Application Express.
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…

816 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

13 Experts available now in Live!

Get 1:1 Help Now