sql server - if exists else query not working sql -


if exists (select @item table_restaurantstransaction mobile=@mobile , orderplaced=0 , restaurant=@restaurantname )   begin  update table_restaurantstransaction set quantity+=@quantity item=@item , mobile=@mobile , orderplaced=0 , restaurant=@restaurantname  end  else  begin  insert table_restaurantstransaction(mobile,transactionid,item,price,decisionstatus,orderplaced,transactiondate,restaurant,quantity) values(@mobile,@transactionid,@item,@price,1,0,getdate(),@restaurantname,@quantity)   end end 

in above query, insert query executed first time when add item. update query getting executed if add same item. if try add new item, insert query not getting executed in else clause.

kindly tell mistake.

i think want test existence of item in if clause:

if exists (select 1            table_restaurantstransaction            item = @item , mobile=@mobile , orderplaced=0 , restaurant=@restaurantname           )  . . . 

however, should learn merge statement in 1 statement.


Comments

Popular posts from this blog

design - Custom Styling Qt Quick Controls -

Unable to remove the www from url on https using .htaccess -