SQL Server 怎么把一个字段变为百分比显示?
在Sqlserver数据库中有一个字段是能力计划率,已经存在数据是Float型的,怎么把这个字段显示为百分比形式?在线等答案...
在Sql server数据库中有一个字段是能力计划率,已经存在数据是Float型的,怎么把这个字段显示为百分比形式?在线等答案
展开
4个回答
展开全部
--sql中保留一位小数的百分比字符串拼接,替换函数,换行符使用
select num
,cast(round(convert(float,isnull((a.Sum_Num-d.Sum_Num),0))/convert(float,c.Sum_Store_Num)*100,1) as varchar(50))+'%' as 报告
FROM tb
做除法运算,分母不为0,round函数保留一位小数。cast函数强制类型转换,转成字符串类型,然后与'%'进行字符串拼接。
展开全部
字段是能力计划率, 应该保存的已经是个百分数了,只要加上%就行了吧?
select CONVERT(VARCHAR,能力计划率) + '%' from 对象表
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
展开全部
SQL Server把字段变为百分比显示代码:
create proc dbo.GetQueNumList
(@quenum as int)
as
begin
set nocount on;
declare @Row_count as int
select @Row_count=count(0) from B表 where QueNum=@QueNum
select
@QueNum as QueNum
,QueName
,cast((sum(case when Grade='A' then 1 else 0 end)*1.0/@QueNum) as numeric(5,2)) as 'A'
,cast((sum(case when Grade='B' then 1 else 0 end)*1.0/@QueNum) as numeric(5,2)) as 'B'
,cast((sum(case when Grade='C' then 1 else 0 end)*1.0/@QueNum) as numeric(5,2)) as 'C'
from
B表
where
QueNum=@QueNum
group by
QueNum
end
create proc dbo.GetQueNumList
(@quenum as int)
as
begin
set nocount on;
declare @Row_count as int
select @Row_count=count(0) from B表 where QueNum=@QueNum
select
@QueNum as QueNum
,QueName
,cast((sum(case when Grade='A' then 1 else 0 end)*100.0/@QueNum) as numeric(5,2)) as 'A'
,cast((sum(case when Grade='B' then 1 else 0 end)*100.0/@QueNum) as numeric(5,2)) as 'B'
,cast((sum(case when Grade='C' then 1 else 0 end)*100.0/@QueNum) as numeric(5,2)) as 'C'
from
B表
where
QueNum=@QueNum
group by
QueNum
end
create proc dbo.GetQueNumList
(@quenum as int)
as
begin
set nocount on;
declare @Row_count as int
select @Row_count=count(0) from B表 where QueNum=@QueNum
select
@QueNum as QueNum
,QueName
,cast((sum(case when Grade='A' then 1 else 0 end)*1.0/@QueNum) as numeric(5,2)) as 'A'
,cast((sum(case when Grade='B' then 1 else 0 end)*1.0/@QueNum) as numeric(5,2)) as 'B'
,cast((sum(case when Grade='C' then 1 else 0 end)*1.0/@QueNum) as numeric(5,2)) as 'C'
from
B表
where
QueNum=@QueNum
group by
QueNum
end
create proc dbo.GetQueNumList
(@quenum as int)
as
begin
set nocount on;
declare @Row_count as int
select @Row_count=count(0) from B表 where QueNum=@QueNum
select
@QueNum as QueNum
,QueName
,cast((sum(case when Grade='A' then 1 else 0 end)*100.0/@QueNum) as numeric(5,2)) as 'A'
,cast((sum(case when Grade='B' then 1 else 0 end)*100.0/@QueNum) as numeric(5,2)) as 'B'
,cast((sum(case when Grade='C' then 1 else 0 end)*100.0/@QueNum) as numeric(5,2)) as 'C'
from
B表
where
QueNum=@QueNum
group by
QueNum
end
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
展开全部
楼主 没有想数字那样的百分比
只要含有百分号 就是字符串了 所以 如果你要真这样整的话 要转换一下数据类型
cast(数字字段*100 as nvarchar(50))+cast('%' as nvarchar(2))
只要含有百分号 就是字符串了 所以 如果你要真这样整的话 要转换一下数据类型
cast(数字字段*100 as nvarchar(50))+cast('%' as nvarchar(2))
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询
广告 您可能关注的内容 |