首页 诗词 字典 板报 句子 名言 友答 励志 学校 网站地图
当前位置: 首页 > 教程频道 > 数据库 > SQL Server >

sql中的数字截取与数字串换的有关问题

2012-01-10 
sql中的数字截取与数字串换的问题我想问一下有谁知道如何将numerica(7,0)的数据类型,转换为numerica(5,0)

sql中的数字截取与数字串换的问题
我想问一下
有谁知道
 
如何将numerica(7,0)的数据类型,转换为numerica(5,0)
就是将7位数的前两位截掉,剩下后五位数字。

[解决办法]
declare @n numeric(7,0)

set @n=1234567.89

select @n,cast(right(str(@n),5) as numeric(5,0))

[解决办法]
create table test(col numeric(7,0))
insert test select 1234567.23
union all select 1234567
union all select 1234
union all select 1234.22

select cast(stuff(cast(col as varchar),1,2, ' ') as numeric(5,0)) from test

drop table test

-------
34567
34567
34
34

(所影响的行数为 4 行)

热点排行
Bad Request.