gaoke 发表于 2018-10-17 09:10:18

SQL函数设计——临时表的使用

INSERT @Plan  SELECT Electrobath_No,sum(Al_P_Plan) AS planTotal
  FROM Al_Product2005 as a
  WHERE (C_date between @dateStart and @dateEnd) and (Al_Status'0') and (Al_P_Fact'0')
  and
  (
  NOT EXISTS
  (
  SELECT *
  FROM Al_Product2005 AS b
  WHERE
  (a.Al_F_Count < b.Al_F_Count) AND (a.Electrobath_No = b.Electrobath_No)
  AND (a.Al_P_count = b.Al_P_count) AND (a.C_Date = b.C_Date) AND (Al_Status0)
  )
  )
  GROUP BY Electrobath_No

页: [1]
查看完整版本: SQL函数设计——临时表的使用