Hi,

I'm using SQL Server 2005.

I have the following SQL which is supposed to pad an integer value with leading zeros. The problem is that it prints 0 instead of 001

Code:
DECLARE @UserID INT
SET @UserID = 1

DECLARE @UtopiaOrderNumber NVARCHAR
SET @UtopiaOrderNumber = (SELECT RIGHT(REPLICATE('0', 3) + CONVERT(NVARCHAR(3), @UserID), 3))

PRINT @UtopiaOrderNumber -- prints 0 instead of 001
The following SQL does select the correct value:

Code:
DECLARE @UserID INT
SET @UserID = 1

SELECT RIGHT(REPLICATE('0', 3) + CONVERT(NVARCHAR(3), @UserID), 3) -- selects 001 as expected
Can anyone let me know what I'm doing wrong?

Thanks,

dlarkin77