在ssrs中是否有办法将数值转换为SSRS中的实际文字?我知道Crystal Reports中有一个“towords”功能,但我不确定它是否是标准的,即可能需要某种API下载。 SSRS中是否提供此功能?如果没有,转换是否可以在SQL Server中执行?我的报告使用SQL Server存储过程。
谢谢
答案 0 :(得分:0)
如果您使用SQL Server返回数据集,则可以使用以下函数
CREATE FUNCTION [dbo].[udf_CurrencyToWords] (@Input numeric(15,2),@Currency tinyint)
RETURNS varchar (8000)
AS
BEGIN
DECLARE @CharInput char(15)
--Pad the input
SET @CharInput = RIGHT('0000000000000' + convert(varchar(15),@Input),15)
DECLARE @Counter tinyint
SET @Counter = 1
DECLARE @InputSub varchar(3)
DECLARE @Group tinyint
DECLARE @Output varchar (8000)
--Get words for each group with some logic for concatenation
WHILE @Counter <= len(@CharInput)-2
BEGIN
SET @InputSub = replace(substring(@CharInput,@Counter,3),'.','')
SET @Group = (len(@CharInput)-@Counter+1)/3
SET @Output =
ISNULL(@Output,'')
+ CASE
WHEN (@Group = 1 AND @InputSub <> 0 AND @Input >= 1.00) OR (@Group = 2 AND @InputSub BETWEEN 1 AND 99 AND @Input > 1000) THEN 'And '
ELSE ''
END
+ CASE
WHEN (@Group = 1 AND @InputSub = 0 AND @Input >= 1.00) OR (@Group = 2 AND @InputSub = 0 AND @Input < 1.00) THEN ''
ELSE [dbo].[udf_CurrencyToWordsSub](@InputSub,@Group,@Currency)
END
SET @Counter = @Counter + 3
CONTINUE
END
--Fix plurals and return a plain Zero if required
SET @Output =
CASE
WHEN right(@CharInput,2) = '01' THEN replace(@Output,'~','')
ELSE replace(@Output,'~','s')
END
SET @Output =
CASE
WHEN @Input < 2 THEN replace(@Output,'#','')
ELSE replace(@Output,'#','s')
END
RETURN ltrim(rtrim(@Output))
END
然后你可以像这样调用这个函数
select dbo.[udf_CurrencyToWords] (8990.03,3)
结果
Eight Thousand, Nine Hundred And Ninety Dollars And Three Cents
只需更改所需货币的@currency
即可select dbo.[udf_CurrencyToWords] (8990.03,1)
Eight Thousand, Nine Hundred And Ninety Pounds And Three Pence