将整型数字转换为大写汉字
2017-01-03 13:40
513 查看
Go
--创建函数(该函数来自csdn,作者不详)
create function [dbo].[padleft]
(
@str varchar(50), --需要填充的字符串
@totalwidth int, --填充后的长度
@paddingchar char(1)--填充使用的字符
)
returns varchar(1000) as
begin
declare @s varchar(100)
set @s = @str
if ( len(@str) < @totalwidth)
begin
declare @i int
declare @strlen int
declare @temp varchar(100)
set @i = 1;
set @strlen = @totalwidth - len(@str)
set @temp = '';
while(@i <= @strlen )
begin
set @temp = @temp + @paddingchar;
set @i = @i + 1;
end
set @s = @temp + @str
end
return (@s)
end
go
--测试示例
declare @table table (id nvarchar(20))
insert into @table
select '1' union all
select '2' union all
select '3' union all
select '4' union all
select '5' union all
select '6'
select dbo.padleft(id,2,'0') as id from @table
--运行结果
/*
id
-------
01
02
03
04
05
06
*/
go
--创建函数(第二版)(作者:maco_wang)
create function padleftV2
(
@sql varchar(200), --需填充的字符串
@char varchar(4), --填充使用的字符
@len int --填充后的长度
)
returns varchar(200)
as
begin
return (right(replicate(@char,@len)+@sql,@len))
end
go
--测试示例
declare @table table(id int)
insert into @table(id)
select 1 union all
select 3 union all
select 6
select dbo.padleftV2(cast(id as varchar),'0',10) as id from @table
--运行结果
/*
id
-------------
0000000001
0000000003
0000000006
*/
--创建函数(该函数来自csdn,作者不详)
create function [dbo].[padleft]
(
@str varchar(50), --需要填充的字符串
@totalwidth int, --填充后的长度
@paddingchar char(1)--填充使用的字符
)
returns varchar(1000) as
begin
declare @s varchar(100)
set @s = @str
if ( len(@str) < @totalwidth)
begin
declare @i int
declare @strlen int
declare @temp varchar(100)
set @i = 1;
set @strlen = @totalwidth - len(@str)
set @temp = '';
while(@i <= @strlen )
begin
set @temp = @temp + @paddingchar;
set @i = @i + 1;
end
set @s = @temp + @str
end
return (@s)
end
go
--测试示例
declare @table table (id nvarchar(20))
insert into @table
select '1' union all
select '2' union all
select '3' union all
select '4' union all
select '5' union all
select '6'
select dbo.padleft(id,2,'0') as id from @table
--运行结果
/*
id
-------
01
02
03
04
05
06
*/
go
--创建函数(第二版)(作者:maco_wang)
create function padleftV2
(
@sql varchar(200), --需填充的字符串
@char varchar(4), --填充使用的字符
@len int --填充后的长度
)
returns varchar(200)
as
begin
return (right(replicate(@char,@len)+@sql,@len))
end
go
--测试示例
declare @table table(id int)
insert into @table(id)
select 1 union all
select 3 union all
select 6
select dbo.padleftV2(cast(id as varchar),'0',10) as id from @table
--运行结果
/*
id
-------------
0000000001
0000000003
0000000006
*/
相关文章推荐
- 【叶子函数分享二十】将整型数字转换为大写汉字
- 将整型数字转换为大写汉字的自定义函数,如转换为'壹贰
- [MSSQL]将整型数字转换为大写汉字
- 【叶子函数分享二十】将整型数字转换为大写汉字
- 将整型数字转换为大写汉字的自定义函数
- [MSSQL]将整型数字转换为大写汉字
- 将小写阿拉伯数字转换成大写的汉字,
- 数字转换为大写汉字
- 金额从数字转换成中文汉字大写的实现
- JS实现将数字金额转换为大写人民币汉字的方法
- 将Android String中的大写汉字数字转换为int或long型数字
- 金额转换,阿拉伯数字的金额转换成中国传统大写汉字的形式
- C#数字转换成大写汉字程序
- JS将数字金额转换为大写人民币汉字
- 爪哇国新游记之二十----将数字转换成中国汉字大写形式
- 数字转换成汉字大写
- JS将数字转换为大写汉字人民币
- java实现数字金额转换成汉字大写金额
- 将输入的阿拉伯数字转换的汉字的大写输出
- 将金额数字转换为汉字大写金额