Question : Pad Numeric string to the left.

Dear Experts,

I have these string numbers (362, 2654,25) and I want pad them to left to make them appear as:
0000362, 0002654, 0000025.

 How can that be done in SQL 2005?

 

Answer : Pad Numeric string to the left.

First create this function :



1:
2:
3:
4:
5:
6:
7:
8:
9:
10:
11:
12:
13:
14:
15:
create function [dbo].[fncGetRendiFormat] (@rendi int)
 
returns nvarchar(7)
 
begin
 
declare @formati nvarchar(7)
 
set @formati = ltrim(rtrim(cast(@rendi as nvarchar(7))))
 
select @formati = REPLICATE('0',7-len(@formati)) + @formati
 
return @formati
 
end
Open in New Window Select All
Random Solutions  
 
programming4us programming4us