I have this request,
Declare @Prcocessrate float declare @item varchar(20) declare @process varchar(20) declare @branch varchar(20) set @item = 'shirt' set @process = 'kt' set @branch = '1' select @Prcocessrate = ProcessPrice from itemwiseprocessrate where itemname=@Item and Process=@process and branchid=@branch
when I run it alone, only 3 steps are displayed in the execution plan, see for yourself.

but i have sp_newBooking procedure like
ALTER PROC sp_newbooking -- other arguements-- AS BEGIN --OTHER FLAGS-- ELSE IF (@Flag = 32) BEGIN declare @ItemId varchar(max),@ProcessRate float --set @BranchId='1' select @ProcessCode = DefaultProcessCode from mstconfigsettings where branchid=@BranchId select @ItemId= DefaultItemId from mstconfigsettings where branchid=@BranchId select @ItemName= ItemName from itemmaster where itemid=@ItemId and branchid=@BranchId select @ProcessRate = ProcessPrice from itemwiseprocessrate where itemname=@ItemName and ProcessCode=@ProcessCode and branchid=@BranchId if(@ProcessRate is not null) select @ItemName as ItemName,@ProcessCode as ProcessCode,@ProcessRate as ProcessRate else select @ItemName as ItemName,@ProcessCode as ProcessCode,'0' as ProcessRate END -- OTHER FLAGS -- END
Now !, when I run this
exec sp_newbooking @flag = 32, @Branchid = 1
In the execution plan, 6 steps are displayed ! Here's a drawing ..!
See Request 4 
Why does he perform 6 steps to execute the same query when executing from this procedure, while he performs 3 steps when executing one? Wtf is that?
sql tsql sql-execution-plan query-optimization
Razort4x
source share