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

数据格式有关问题

2012-02-03 
数据格式问题?有如下表:IDFQtyA1.00000B2.00000A3.30000这是表的结构,不能改的,按ID汇总,用一变量显示如下

数据格式问题?
有如下表:
ID           FQty
A             1.00000

B             2.00000

A             3.30000


这是表的结构,不能改的,按ID汇总,
用一变量显示如下格式:

4.5+1


如:我是这样用的,但没有实现如上格式:
select   @FNOte= '+ '+ltrim(sum(convert(dec(10,1),FQty))

stuff....


最终可以显示:4.5+1.0,那如何显示如上格式呢?

[解决办法]
select @FNOte= '+ '+ltrim(sum(convert(dec(10,0),FQty))
[解决办法]
刚才错了,不好意思i,这样应该对了
create table #temp
(ID varchar(10),
FQty decimal(10,5)
)
insert into #temp
select 'A ',1.00000 union all select 'B ',2.0000 union all select 'A ',3.30000
select * from #temp


select
case
when cast(FQty as decimal(10,1))-cast(FQty as decimal(10,0))=0.0
then cast(cast(FQty as decimal(10,0)) as varchar(50))
when cast(FQty as decimal(10,1))-cast(FQty as decimal(10,0)) <> 0.0
then cast(cast(FQty as decimal(10,1)) as varchar(50))
end
from
#temp

------------------

1
2
3.3

热点排行