sql的padleft

/*
SELECT dbo.fn_PadLeft('8', '0', 6)  
*/
create function fn_PadLeft(@num nvarchar(16),@paddingChar char(1),@totalWidth int)
returns nvarchar(16) as
begin
declare @curStr nvarchar(16)
select @curStr = isnull(replicate(@paddingChar,@totalWidth - len(isnull(@num ,0))), '') + @num
return @curStr
end

  

posted @ 2015-06-25 16:19  哈哈2222  阅读(233)  评论(0编辑  收藏  举报