日期:2014-05-19  浏览次数:20585 次

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 行)