关于数值的小数位数显示的问题。

本文介绍了一个SQL函数f_getQuantityDecimal,用于根据指定的小数位数来截取数值。该函数接受两个参数:数量值和所需保留的小数位数,并返回经过格式化的字符串形式的数量值。

简述:在物料相关属性中,有字段 存储小数位数,取值 0、1、2 ...


使用示例:

				,dbo.f_getQuantityDecimal(mo.quantity,item.quantityDecimal) as quantity


函数源码:


USE [db_NLMRPII]
GO
/****** 对象:  UserDefinedFunction [dbo].[f_getQuantityDecimal]    脚本日期: 08/09/2011 10:36:52 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO

-- =============================================
-- Author:		<Author,,Name>
-- Create date: <Create Date, ,>
-- Description:	<Description, ,>
-- =============================================
ALTER FUNCTION [dbo].[f_getQuantityDecimal]
(
	-- Add the parameters for the function here
	 @quantity decimal(28,10)
	,@decimal smallint
)
RETURNS varchar(50)
AS
BEGIN
	-- Declare the return variable here
	DECLARE @ResultVar varchar(50)

	-- Add the T-SQL statements to compute the return value here
	
	IF( @quantity = null ) begin set @quantity = 0 end
	IF( @decimal  = null ) begin set @decimal  = 0 end
		
	select @ResultVar =
		left( 
			@quantity
			, CHARINDEX( '.', @quantity ) 
				+ ( case 
						when @decimal = 0 
						then -1 
						else @decimal 
					end ) 
			)
	
	

	-- Return the result of the function
	RETURN @ResultVar

END


评论
成就一亿技术人!
拼手气红包6.0元
还能输入1000个字符
 
红包 添加红包
表情包 插入表情
 条评论被折叠 查看
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值