USE [cpqaAnswers]
GO
CREATE TABLE [cpqa].[tbl_RP_zeropadSolution005]
(
P_Id int,
amount varchar(50),
name nvarchar(10)
)
INSERT INTO [cpqa].[tbl_RP_zeropadSolution005]
VALUES(1, '9', 'Tintin'),
(2, '361','TakTak'),
(3, '542','Toucan'),
(4, '2010','Tallidego')
SELECT * FROM [cpqa].[tbl_RP_zeropadSolution005]
SELECT * FROM [cpqa].[tbl_RP_zeropadSolution005] ORDER BY [amount]
Compare previous two SELECT to this:
SELECT [P_Id], LEFT(REPLICATE('0', 6), 6 - LEN([amount])) + [amount] AS [zeropadded_amount], [name] FROM [cpqa].[tbl_RP_zeropadSolution005]
SELECT [P_Id], LEFT(REPLICATE('0', 6), 6 - LEN([amount])) + [amount] AS [zeropadded_amount], [name] FROM [cpqa].[tbl_RP_zeropadSolution005] ORDER BY [zeropadded_amount] DESC
Copy and paste the above into New Query and hit F5 to see.