新建的时候就报这个错误! create PROCEDURE [dbo].[P_SaleMonthReport]--订单销售订单(月报)
    (
      @BeginDate datetime,--开始日期
      @EndDate datetime --结束日期
    )
AS 
    BEGIN
        select a.ShopId,--店铺ID
        isnull(s.ShopName,0) ShopName,--店铺名称
        a.SaleMonth,--月份
        ISNULL(A.OrderMoney,0.00)OrderMoney,--订的金额
        ISNULL(a.OrderCount,0) OrderCount,--订的数量
        ISNULL(a.CostMoney,0.00)CostMoney,--订的成本
        ISNULL(A.ShouldPay,0.00) ShouldPay,--应付金额
        ISNULL(PayedMoney,0.00)PayedMoney,--已付金额
        ISNULL(D.RefundMoney,0.00) RefundMoney,--退款金额
        ISNULL(b.RtnOrderCount,0) RtnOrderCount,--退货单数量
        ISNULL(C.RmaOrderCount,0) RmaOrderCount,--退货单数量
CASE WHEN ISNULL(a.CostMoney,0.00) = 0.00 then '0.00%' else Convert(nvarchar(20),
CAST(((ISNULL(a.PayedMoney,0.00) - ISNULL(d.RefundMoney,0.00) - ISNULL(a.CostMoney,0.00)) * 100 / ISNULL(a.CostMoney,0.00)) AS DECIMAL(18,2)))+'%' end Profit--毛利率
from
(select ShopId, convert(nvarchar(7),CreateTime,120) as SaleMonth,COUNT(1) OrderCount,SUM(OrderMoney) OrderMoney,SUM(CostMoney) CostMoney,SUM(ShouldPay) ShouldPay,SUM(PayedMoney) PayedMoney from Sales_Order where buytime >= @BeginDate and buytime <= @EndDate group by ShopId,Convert(nvarchar(7),buytime,120)
) a--这个理 from(...)a 里面的问题好像
full join
(select ShopId,Convert(nvarchar(7),CreateTime,120) RtnTime,count(1) RtnOrderCount from Sales_RtnOrder where RtnType = 1 and CreateTime >= @BeginDate and CreateTime <= @EndDate group by ShopId,Convert(nvarchar(7),CreateTime,120))b on b.ShopId = a.ShopId and b.RtnTime = a.SaleMonth 
full join
(select ShopId,Convert(nvarchar(7),CreateTime,120) RmaTime,count(1) RmaOrderCount from Sales_RtnOrder where RtnType = 2 and CreateTime >= @BeginDate and CreateTime <= @EndDate group by ShopId,Convert(nvarchar(7),CreateTime,120))c on c.ShopId = a.ShopId and c.RmaTime = a.SaleMonth 
full join
(select shop.ID ShopId,Convert(nvarchar(7),CAST(Created AS DateTime),120) RefundTime,SUM(CAST(RefundFee AS decimal(18,2))) RefundMoney from dbo.Finance_Refund refund left outer join Top_Shop shop on shop.NickName = refund.SellerNick where refund.Created >= @BeginDate and Created <= @EndDate group by shop.ID,Convert(nvarchar(7),CAST(Created AS DateTime),120))d on d.ShopId = a.ShopId and d.RefundTime = a.SaleMonth
left join 
(select ID,ShopName from Top_Shop) s on s.ID = a.ShopId 
    END