I have a question about SQL Server: how to add leading three 000 (zeros) while id does not have leading zeros in SQL Server?
CREATE TABLE [dbo].[ids] ( [id] [VARCHAR](50) NULL, [name] [VARCHAR](50) NULL ) ON [PRIMARY] GO INSERT INTO [dbo].[ids] ([id], [name]) VALUES (N'09', N'abc') GO INSERT INTO [dbo].[ids] ([id], [name]) VALUES (N'0098', N'de'), (N'987', N'j'), (N'00056', N'i'), (N'6', N'z'), (N'0908', N'u'), (N'99999999', N'u'), (N'7522323838483', N'i') GO Based on above data I want output like below :
name | id --------+----------- abc | 0009 de | 00098 j | 000987 i | 00056 z | 0006 u | 000908 u | 00099999999 i | 0007522323838483 I tried like this:
SELECT RIGHT('000' + id, 3) id, [name] FROM [dbo].[ids] but above query is not returning the expected result.
Can you please tell me how to write a query to achieve this task in SQL Server?

RIGHT:'000' + id