简述:在物料相关属性中,有字段 存储小数位数,取值 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