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 Mike Lewis on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

leading zerso dropping off.

Status
Not open for further replies.

Neozero

MIS
Jul 7, 2000
49
0
0
US
I am writing a statment to autogenerate a number. The number is 5 digits, but the number that the auto generate is on is only 3. what is happening is that when the number generates, it should show 00545 but instead it is showing 545. What syntax should be used to make the leading zeros show up? any help would be appreciated.
 
If the return value is numeric then you cannot assume leading zeros will be displayed. If the number is converted to be displayed as a string then this can be done.

Try:

Code:
select right("00000" + convert(varchar(5),@your_number),5)

Please note though that if you try and convert this back to an int, the leading zeros will be removed. If you are passing this data around then try passing the numeric value (345) and the string version (00345).

Hope that helps.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top