sql - 如何限制 SQL Server 函数舍入 Money 返回值
问题描述
我做了一个函数来获取带有返回值的转换率,但是为什么 sql server 对数据输出进行四舍五入。
我在 SQL Server 上做了一个标量函数,返回输出资金
CREATE FUNCTION CurrencyRate(
-- Add the parameters for the function here
@FromCurr CHAR(3),
@ToCurr CHAR(3),
@Date_Tran DATE)
RETURNS MONEY
AS
BEGIN
-- Declare the return variable here
DECLARE @CurrencyRate MONEY;
-- the T-SQL statements to compute the return value here
SELECT @CurrencyRate = CAST(tc.scale AS MONEY)
FROM dbo.TCurrencyConverter tc
WHERE @Date_Tran BETWEEN tc.start_date AND tc.end_date
AND tc.currency_id_1 = @FromCurr
AND tc.currency_id_2 = @ToCurr;
-- Return the result of the function
RETURN @CurrencyRate;
END;
GO
我希望输出是0.000070550000000
,但实际输出是0.0001
。
解决方案
这是货币数据类型的最大sqlserver
大小
92233720368547.9999
您可以使用 numeric() 作为返回类型。
cast('0.000070550000000' as numeric(18,18))
推荐阅读
- c++ - 如何实现这个集合模板类的构造函数和析构函数?
- pylint - 在 mac 终端中无法看到运行 pylint 的详细报告
- php-deployer - 如何正确安装部署程序?
- python - 无法使用 Selenium 和 Python 播放 YouTube 视频
- android - 如何明智地更改cardview的背景颜色?
- python - 有什么办法可以将 bs4.element.ResultSet 转换为 bs4.BeautifulSoup?
- python - Python3 AWS Lambda - 向需要 VPN 的域发出发布请求
- javascript - Uncaught SyntaxError: Unexpected token '<' plugins.js:1 和 Uncaught SyntaxError: Unexpected token '<' active.js:1
- r - 如何将变量名称下方的“变量描述”从 R 导出为 csv 或 excel 格式?
- r - 当文件存在但可以读取时,如何使用 read_excel 进行错误处理?