日期:2014-05-18  浏览次数:20398 次

数据格式问题?
有如下表:
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