Consultor Eletrônico



Kbase P187255: SQL: How to format an integer number to have leading zeros on the left?
Autor   Progress Software Corporation - Progress
Acesso   Público
Publicação   5/6/2011
Status: Unverified

GOAL:

SQL: How to format an integer number to have leading zeros on the left?

GOAL:

How to keep leading zeros ( on the left) when retrieving an integer using a SELECT statement?

GOAL:

How to return the CustNum INTEGER field as a 9 DIGIT string with leading zeros?

FACT(s) (Environment):

All Supported Operating Systems
Progress 9.1x
OpenEdge 10.x

FIX:

The following SELECT statement will return the CVustNum as a string of 9 digits with leading zeros on the left side. Please be aware that if the the CustNum has more than 9 digits to start with, only the 9 digits ( counting from the right) will be returned. In other words, the string will be left truncated to 9 digits:
SELECT RIGHT('000000000' + CONVERT('VARCHAR',Custnum),9) FROM pub.customer