In SQL Server 2000 how do you add {n} number of 0's to a nchar(n)?
I'm using SQL Server 2000 and I'm not sure if there is already a function to add any number of 0's to an nchar(n)
, or if this is best done in a function?
Does this look correct开发者_运维知识库
proc repeatingCh
@n int, -- i/p n to some number of characters
@ch nchar(1), --i/p character
@ch_n nchar(n) out
as
begin
declare @ch_n as nchar(n)
set @ch_n = ''
for(i=1 to n)
begin
@ch_n = @ch_n + @ch
end
return 1
end
I want to call it in a sproc or... most likely a function and return the repeating characters.
me again ;)
You can use REPLICATE
for this:
SELECT REPLICATE('0', 10)
ex your record is unsized col1 55 66 777 888
you need all in 6 digit
if select replicate('0',6-len(col1))++col1
or
declare @input varchar(10)
set @input = '1234'
select replicate('0',10-len(@input))++@input
精彩评论