Solved

generating 8-digit sequence

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

Windows Server 2016: All you need to know

Learn about Hyper-V features that increase functionality and usability of Microsoft Windows Server 2016. Also, throughout this eBook, you’ll find some basic PowerShell examples that will help you leverage the scripts in your environments!

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
SQL anywhere 11 databases 1 90
Trigger usage 2 75
TypeError: Users.save is not a function 3 60
DBF to ... Converter 5 81
This article describes some very basic things about SQL Server filegroups.
As technology users and professionals, we’re always learning. Our universal interest in advancing our knowledge of the trade is unmatched by most industries. It’s a curiosity that makes sense, given the climate of change. Within that, there lies a…
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…

808 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