Link to home
Start Free TrialLog in
Avatar of sherbug1015
sherbug1015Flag for United States of America

asked on

Padding a number with leading zero

I am making a folder cabinet table where the user can add up to 30 levels of folders

The table structure looks like the attached.

If my next record was a child of folderID 3.  I would need the folderIDPath to equal 23.03.04 (4 would be the identity key of the new record going in)

DepartmentID.ParentID.FolderID  with leading zeros for ParentId/FolderID

Anyone have any idea how I can write this in SQL Server?

Thanks.



filecabinets.xlsx
Avatar of PortletPaul
PortletPaul
Flag of Australia image

this will pad a zero, 1 or 2 digit integer:

RIGHT('00' + CONVERT(varchar,[number_column],2) ,2)

change [number_column] to the column name needed
if nulls get in the way try this

RIGHT('00' + ISNULL(CONVERT(varchar,[number_column],2),'00') ,2)
ASKER CERTIFIED SOLUTION
Avatar of PortletPaul
PortletPaul
Flag of Australia image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial