Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations gkittelson on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

How to add leading zeros to a column?

Status
Not open for further replies.

goyalpdm

Programmer
Jan 11, 2003
42
US
Can I add leading zeros to a column? Requirement arises from needs of a business user who wants to do sorting on a column.

Issue is - column is a character column but contains numeric data. So when user sorts, 693 comes after 5123. Character column will sort it based on first digit and so on.

Can't change data model as this is a legacy system. So a solution? Add leading zeros to data of this column. So, 693 will become 0693 and will appear before 5123.

Am loading using AWK. Can I check for column length in AWK? And if length is less then 5, add zeros to the data in do-while loop etc.

Please help.

Cheers,
Sachin
 
man sprintf

vlad
+----------------------------+
| #include<disclaimer.h> |
+----------------------------+
 
man sort for the -n option.

Hope This Helps, PH.
Want to get great answers to your Tek-Tips questions? Have a look at FAQ219-2884 or FAQ222-2244
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top