Click here to Skip to main content
16,004,529 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
See more: (untagged)
How to execute below procedure for insert update


SQL
create procedure InsertData
as begin
declare @Result as int,@segment varchar(3), @tradeID bigint = null,@accountID varchar(20),
@symbol1 varchar(20),@tradedqty bigint,@tradeprice money, 
@transtype int,@tradetime varchar(20),@traderID bigint, 
@locationID varchar(25),@orderentrytime varchar(20),
@process1 int,@isin varchar(20)
exec CheckUniqueTradeID @segment,null,@accountID,@symbol1,@tradedqty,@tradeprice,@transtype,
@tradetime,@traderID,@locationID,@orderentrytime,@process1,@isin,@Result out
if  @Result = 1
begin
insert into [dbo].[consolidated](segment,tradeID,accountID,symbol1,
tradedqty,tradeprice,transtype,tradetime,traderID,locationID,
tradevalue,orderentrytime,process1,isin)
select [segment],
CONVERT(VARCHAR(10),[tradeID])+[transtype] AS NewTrans,
 [accountID],
 [symbol]
 ,[tradedqty],
 CASE WHEN [process1] = 1 THEN [tradeprice]/100 END AS [tradeprice],
case when [process1]  =1 then case when [transtype] = 'B' THEN 1 WHEN [transtype] = 'S' THEN 2 end
end AS [transtype],
  [tradetime1],
  [traderID],
  [locationID],
 CASE WHEN [process1] = 0 THEN [tradedqty]*[tradeprice]
 END AS [tradevalue],
 [orderentrytime],
  CASE WHEN [process1] = 0 THEN 1 ELSE 0 END AS [process1],
  [isin]
from [dbo].[bse_trade] where process1 = 0
 end 
 if @Result = 0
 begin
 exec UpdateParameters
 end
 update bse_trade set process1 = 2
 where process1 = 1 
 end
Posted
Updated 25-Aug-13 21:32pm
v2
Comments
Anele Ngqandu 26-Aug-13 3:46am    
You want to call this stored procedure from your code?
Member 10216798 26-Aug-13 4:34am    
no i want to exec in sql but now i done it its working but when first time i m inserting record it is inserted but again i m inserting this above record that time its update but there is going duplicate record by update so i dont want to add duplicate record so plz tell me what to do in procedure

1 solution

Try this SQL Query:
SQL
EXEC InsertData

More information: http://technet.microsoft.com/en-us/library/ms189915.aspx[^]
 
Share this answer
 
Comments
Member 10216798 26-Aug-13 4:31am    
thanx i done it but there is problem is that when i m inserting record first time then record insert and again i m exec procedure so after that again all this record update so all record agin inserted so what is use of my chckuniquetradeID procedure i mean i dont want to go duplicate record so what i do for that
Thomas Daniels 26-Aug-13 4:34am    
If you want to update a record, then use the UPDATE Statement
Member 10216798 26-Aug-13 4:37am    
ya i used update but duplicate record inserting i dont want to insert duplicate record
Thomas Daniels 26-Aug-13 4:39am    

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