deepikamm (1/31/2012)
after seeing sp_executesql in sqlservercentral homepage,I started searching about it.
Seeing !!!? Didn't you read the article?
David shows the use of SP_ExecuteSQL when he executes this code in his article:
USE AdventureWorks
go
DECLARE
@EmployeeID int,
@Statement nvarchar(2000),
@ParamDefinitions nvarchar(2000)
SET @Statement = N'SELECT * FROM HumanResources.Employee WHERE ManagerId=@ManagerID AND MaritalStatus=@MaritalStatus'
SET @ParamDefinitions = N'@ManagerID INT,@MaritalStatus char(1)'
exec sp_executesql @statement, @ParamDefinitions,@ManagerID=21,@Maritalstatus='S'
He clearly explains how SP_ExecuteSQL helps to use the plan stored in the cache even after chainging the parameter values :cool:.