sp-executesql

EXEC sp_executesql with multiple parameters

倖福魔咒の 提交于 2019-11-26 12:29:23
问题 How to pass the parameters to the EXEC sp_executesql statement correctly? This is what I have now, but i\'m getting errors: alter PROCEDURE [dbo].[usp_getReceivedCases] -- Add the parameters for the stored procedure here @LabID int, @RequestTypeID varchar(max), @BeginDate date, @EndDate date AS BEGIN -- SET NOCOUNT ON added to prevent extra result sets from -- interfering with SELECT statements. SET NOCOUNT ON; declare @statement nvarchar(4000) set @statement = N\'select SentToLab, FROM dbo

Entity Framework 4.2 exec sp_executesql does not use indexes (parameter sniffing)

自古美人都是妖i 提交于 2019-11-26 08:27:17
问题 I\'m encountering some major performance problems with simple SQL queries generated by the Entity Framework (4.2) running against SQL Server 2008 R2. In some situations (but not all), EF uses the following syntax: exec sp_executesql \'DYNAMIC-SQL-QUERY-HERE\', @param1... In other situations is simply executes the raw SQL with the provided parameters baked into the query. The problem I\'m encountering is that queries executed with the sp_executesql are ignoring all indexes on my target tables,