We have a heavily used GUI that displays specific business data in a pivot.A stored procedure is used to create the pivot, using dynamic SQL.The SP is using EXEC sp_executesql with parameters in the following way:SET @SQL = 'select * from (select '+@Cols+' from #X) StdP PIVOT (COUNT(DateStamp) FOR DateStamp IN ('+@Pivot+')) as PVT order by '+@Cols2+''EXEC sp_executesql @SQL, N'@_Cols varchar(100), @_Cols2 varchar(100), @_Pivot varchar(5000)', @_Cols = @Cols, @_Cols2 = @Cols2, @_Pivot = @Pivot****@Pivot can and most of the time is, will be different on each execution.The plan cache is overflowing with many prepared, single use execution plans.How can this be avoided?Thanks in advance.
↧