samedi 16 juillet 2016

Filling result with prefix 0 to a fixed width

I have the following challenge. The goal is to create fixed-width fields of 6 characters. If the table field only contains three characters, then there should be three characters prefixed with 0. Example

the source is a table with account limits

Limit

201

4000

result

Limit

000201

004000

I have the following code, but this will postfix the value, and I need to prefix the limit values with 0's.

SELECT REPLACE(CAST(LIMIT AS NCHAR(6)), SPACE(1),'0') AS Accountlimit FROM DWH.limit

Aucun commentaire:

Enregistrer un commentaire