Solved

generating 8-digit sequence

Posted on 2000-05-02
4
492 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

How your wiki can always stay up-to-date

Quip doubles as a “living” wiki and a project management tool that evolves with your organization. As you finish projects in Quip, the work remains, easily accessible to all team members, new and old.
- Increase transparency
- Onboard new hires faster
- Access from mobile/offline

Join & Write a Comment

In today’s complex data management environments, it is not unusual for UNIX servers to be dedicated to a particular department, purpose, or database.  As a result, a SAS® data analyst often works with multiple servers, each with its own data storage…
This article explains all about SQL Server Piecemeal Restore with examples in step by step manner.
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…

762 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

21 Experts available now in Live!

Get 1:1 Help Now