This is a known "problem"/"solution" in T-SQL (regardless of version 2000,2005,2008). but i don't know what is the of this particular case.i have two procedures (using AdventureWorks):1.create procedure test1@date_to smalldatetime,@date_from smalldatetimeasselect d.id,d.Q,d.cash,d.pricefrom(select count(1) as id ,sum(OrderQty) as Q ,sum(UnitPrice)/100 as cash ,p_d.UnitPrice as pricefrom Purchasing.PurchaseOrderDetail as p_d join Purchasing.PurchaseOrderHeader as p on p_d.PurchaseOrderID = p.PurchaseOrderIDwhere p_d.DueDate between @date_from and @date_togroup by p_d.PurchaseOrderID ,p_d.DueDate ,p_d.UnitPrice) as dgroup by d.Q,d.id,d.price,d.cashgo
2.create procedure test2@date_to smalldatetime,@date_from smalldatetimeasdeclare @date1 smalldatetimedeclare @date2 smalldatetimeset @date1=@date_toset @date2=@date_fromselect d.id,d.Q,d.cash,d.pricefrom(select count(1) as id ,sum(OrderQty) as Q ,sum(UnitPrice)/100 as cash ,p_d.UnitPrice as pricefrom Purchasing.PurchaseOrderDetail as p_d join Purchasing.PurchaseOrderHeader as p on p_d.PurchaseOrderID = p.PurchaseOrderIDwhere p_d.DueDate between @date1 and @date2group by p_d.PurchaseOrderID ,p_d.DueDate ,p_d.UnitPrice) as dgroup by d.Q,d.id,d.price,d.cashgo
First procedure uses procedure_parameters in where condition of select statement, where are the second procedure declares local variables (read from procedure_parameters) in where condition of select statement.the second procedure executes much faster than the first one (especially visible if you have huge database - which adventureworks is not).Can anyone explain, what is (how to address) the name of this common/known problem/issue? :)thank you