存储过程:
USE [ZM]
GO
/****** Object: StoredProcedure [dbo].[UP_SalesAnalyis] Script Date: 03/31/2012 08:27:40 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
-- =============================================
-- Author: <David Gang>
-- Create date: <2012-03-30>
-- Description: <销售分析按区域客户产品>
-- =============================================
ALTER Procedure [dbo].[UP_SalesAnalyis]
as
begin
declare @yyyymm char(6)
set @yyyymm=datepart(year,getdate())*100+datepart(month,getdate())
------------------------------销售区域--------------------------------
select Customers,
sum(Quantities) Quantities,
sum(Amount) Amount,
sum([Cost of Sales]) as [Cost of Sales],
sum(Amount)-sum([Cost of Sales]) as [Gross Margin]
into #base