insert和select查询的组合

insert和select查询的组合

本文介绍了insert和select查询的组合的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

insert into TempTable1STOCKDETAILS (PRODUCT_NO,PRODUCT_NAME,QTY_IN,UNIT_COST,FROM_DATE,TO_DATE)
(SELECT  a.PRODUCT_NO PRODUCT_NO, a.PRODUCT_NAME PRODUCT_NAME, SUM(A.QTY_IN) as QTY_IN,AVG(A.UNIT_COST) AS UNIT_COST
FROM STOCKDETAILS A  WHERE  a.WH_NO='WH1' AND a.STOCK_JR IN ('IN') AND a.STOCK_DATE BETWEEN
Convert(DATETIME,'29-09-2014',105) AND Convert(DATETIME,'30-09-2014',105)GROUP BY a.PRODUCT_NO , a.PRODUCT_NAME ) ,Convert(DATETIME,'29-09-2014',105),Convert(DATETIME,'30-09-2014',105)











此处PRODUCT_NO,PRODUCT_NAME,QTY_IN,UNIT_COST点击使用精选查询,并且

FROM_DATE ,TO_DATE等于转换(DATETIME,'2 9-09-2014',105),转换(DATETIME,'30 -09-2014',105)






here PRODUCT_NO,PRODUCT_NAME,QTY_IN,UNIT_COST get by using select query ,and
FROM_DATE,TO_DATE equals to Convert(DATETIME,'29-09-2014',105),Convert(DATETIME,'30-09-2014',105)

推荐答案

INSERT INTO TempTable1STOCKDETAILS (PRODUCT_NO,PRODUCT_NAME,QTY_IN,UNIT_COST,FROM_DATE,TO_DATE)
SELECT  a.PRODUCT_NO, a.PRODUCT_NAME, SUM(A.QTY_IN) AS QTY_IN, AVG(A.UNIT_COST) AS UNIT_COST, '29-09-2014' AS FROM_DATE, '30-09-2014' AS TO_DATE
FROM STOCKDETAILS A  WHERE  a.WH_NO='WH1' AND a.STOCK_JR = 'IN' AND a.STOCK_DATE BETWEEN '29-09-2014' AND '30-09-2014'
GROUP BY a.PRODUCT_NO, a.PRODUCT_NAME


这篇关于insert和select查询的组合的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

08-01 19:40