Click here to Skip to main content
15,886,110 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
SQL
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)





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)
Posted
Updated 16-Oct-14 20:12pm
v2
Comments
Garth J Lancaster 17-Oct-14 2:14am    
so, what's your question ?
navya chowdary 17-Oct-14 2:16am    
it giving errors as
Msg 116, Level 16, State 1, Line 4
Only one expression can be specified in the select list when the subquery is not introduced with EXISTS.
Msg 109, Level 15, State 1, Line 1
There are more columns in the INSERT statement than values specified in the VALUES clause. The number of values in the VALUES clause must match the number of columns specified in the INSERT statement.
aarif moh shaikh 17-Oct-14 2:16am    
What's your actual problem
King Fisher 17-Oct-14 2:16am    
Error?
Jitendra Ku. Sahoo 17-Oct-14 2:17am    
No one can replay as your question is not clear :(

1 solution

Try this:
SQL
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
 
Share this answer
 
Comments
navya chowdary 17-Oct-14 7:31am    
THANK YOU Mciej Los
Maciej Los 17-Oct-14 7:34am    
You're very welcome ;)

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900