USE [ufida_TSGY_Data]
GO
/****** Object: UserDefinedFunction [dbo].[fn_GetMonthQtyPriceAmount] Script Date: 12/11/2009 00:07:41 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
/**********************************
产品销量明细统计表 -- 计算每月的销量
Author : 马琪玉
Date : 2009年12月11日0:20:58
传入参数:
@Year
数据类型:Varchar(50)
描述:统计年份
@Month
数据类型:Varchar(50)
描述:统计月份
@ItemCode
数据类型:Varchar(50)
描述:需要统计的料品
返回值:
@QtyPriceAmountSum
数据类型:Decimal
描述:指定年月下的料品总销量
**********************************/
CREATE FUNCTION [dbo].[fn_GetMonthQtyPriceAmount]
(
@Year Varchar(50),
@Month Varchar(50),
@ItemCode Varchar(50)
)
RETURNS Decimal
AS
BEGIN
Declare @QtyPriceAmountSum Decimal;
begin
select @QtyPriceAmountSum = sum(A1.QtyPriceAmount) from SM_Ship as A left join [SM_ShipLine] as A1 on A1.ItemInfo_ItemCode = @ItemCode
where YEAR(A.ApproveDate)=@Year and Month(A.ApproveDate) = @Month
if(@@rowcount = 0) set @QtyPriceAmountSum = 0
else if(@QtyPriceAmountSum is null) set @QtyPriceAmountSum=0
end
return @QtyPriceAmountSum
END;
GO