Click here to Skip to main content
15,915,770 members
Please Sign up or sign in to vote.
5.00/5 (1 vote)
See more:
SQL
ALTER Procedure [dbo].[test2]
@Table_No int ,
@OID int

AS

Begin


Insert into dbo.Sales(Item_ID,Qty,Price,OID,SaleDate,CID)
values ((Select Item_ID , SUM(Qty)as Qty ,SUM(Price) as Price from dbo.TemperoryOrder where Table_No=@Table_No AND OID=@OID group by Item_ID),@OID,GETDATE(),null)

End
Posted
Updated 14-Mar-14 20:11pm
v2
Comments
What is the issue?

You just need to change the syntax and not use VALUES because you can't mix it with a SELECT. All you need to use is a SELECT.

SQL
INSERT INTO dbo.Sales(Item_ID, Qty, Price, OID, SaleDate, CID)
SELECT Item_ID, SUM(Qty), SUM(Price), @OID, GetDATE(), null
FROM dbo.TemperoryOrder
WHERE Table_No = @Table_No AND OID = @OID
GROUP BY Item_ID
 
Share this answer
 
Comments
syedwajid 14-Mar-14 17:13pm    
Thanks alot Dev...Its working
ZurdoDev 14-Mar-14 17:40pm    
Glad to hear it.
Hi
Select sub query need not to write inside the braces '()' just write as

SQL
Insert into table A(col1, col2, col3)
  Select @col1, @Col2, @Col3 from table B Were 1=1 



Here you can have any condition at where clause.
 
Share this answer
 
v2

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