请教,现在有汇总报表SQL存储过程,V_out_detail2019为一个明细表,表中sheet_date为日期列。怎么做窗口录入@all_no,@date_fr,@date_to后执行。
CREATE proc [dbo].[pro_sal8]
@all_no varchar(100),
@date_fr datetime,
@date_to datetime
AS
begin
SELECT cust_name1 as 客户名称,
SUM(case when goods_type like '10%' then total_sheet_amt else 0 end) as 产品1,
SUM(case when goods_type like '15%' then total_sheet_amt else 0 end) as 产品2,
SUM(case when goods_type like '200%' then total_sheet_amt else 0 end) as 配件,
SUM(total_sheet_amt) as 合计
FRO M V_out_detail2019
WHERE CONVERT (char(10),sheet_date,120) between @date_fr and @date_to
and sheet_sta in ('1','2')
and (@all_no = 'ALL' or cust_name1 like '%'+@all_no+'%' )
GROUP BY cust_name1
order by SUM(total_sheet_amt) desc
end