日期:2014-05-18 浏览次数:20518 次
CREATE PROCEDURE YourPROCname ( @BeginDate VARCHAR(30) , @EndDate VARCHAR(30) , @saleBy INT ) AS BEGIN SELECT SaleDay , SUM(orderMoney) AS OrderMoney , SUM(OrderQty) AS OrderQty , SUM(RtnCash) AS RtnCash , SUM(RtnCount) AS RtnCount FROM ( SELECT CONVERT(DATE, CreateTime) AS SaleDay , SUM(shouldpay) AS OrderMoney , COUNT(orderId) AS OrderQty , 0 AS RtnCash , 0 AS RtnCount FROM dbo.Sales_Order--订单销售表 WHERE status >= 3 AND CreateTime > CONVERT(DATE, @BeginDate) AND CreateTime < CONVERT(DATE, DATEADD(day, 1, @EndDate)) AND saleBy = @saleBy GROUP BY CONVERT(DATE, CreateTime) UNION ALL SELECT CONVERT(DATE, CreateTime) AS SaleDay , 0 AS OrderMoney , 0 AS OrderQty , SUM(RtnCash) AS RtnCash , COUNT(*) AS RtnCount FROM dbo.Sales_RtnOrder--订单退换表 WHERE status >= 1 AND CreateTime > CONVERT(DATE, @BeginDate) AND CreateTime < CONVERT(DATE, DATEADD(day, 1, @EndDate)) GROUP BY CONVERT(DATE, CreateTime) ) a GROUP BY SaleDay--销售天数 END --执行存储过程 EXEC YourPROCname '2010-02-01','2011-02-01',45