![]() | |
#21
| |||
| |||
|
|
SQL Server 2005 Database Engine Tuning Advisor informs me that I should replace query 1 below with the syntax in query 2 below. I’m just not seeing the reason since both the “SELECT” statements optimization plans are stored for reuse. Am I missing something? Mike. Query 1 EXEC sp_executesql N'SELECT FirstName, LastName, Company, StreetAddress, City, State, ZIP5, ZIP4 FROM Customers WHERE City = @P1 AND State = @P2', N'@P1 char(32), @P2 varchar(32)', 'Poedunk', 'Iowa' Query 2 DECLARE @P1 varchar(32) DECLARE @P2 varchar(32) SET @P1 = 'Poedunk' SET @P2 = 'Iowa' SELECT FirstName, LastName, Company, StreetAddress, City, State, ZIP5, ZIP4 FROM Customers WHERE City = @P1 AND State = @P2 |
#22
| |||
| |||
|
|
SQL Server 2005 Database Engine Tuning Advisor informs me that I should replace query 1 below with the syntax in query 2 below. I’m just not seeing the reason since both the “SELECT” statements optimization plans are stored for reuse. Am I missing something? Mike. Query 1 EXEC sp_executesql N'SELECT FirstName, LastName, Company, StreetAddress, City, State, ZIP5, ZIP4 FROM Customers WHERE City = @P1 AND State = @P2', N'@P1 char(32), @P2 varchar(32)', 'Poedunk', 'Iowa' Query 2 DECLARE @P1 varchar(32) DECLARE @P2 varchar(32) SET @P1 = 'Poedunk' SET @P2 = 'Iowa' SELECT FirstName, LastName, Company, StreetAddress, City, State, ZIP5, ZIP4 FROM Customers WHERE City = @P1 AND State = @P2 |
#23
| |||
| |||
|
|
SQL Server 2005 Database Engine Tuning Advisor informs me that I should replace query 1 below with the syntax in query 2 below. I’m just not seeing the reason since both the “SELECT” statements optimization plans are stored for reuse. Am I missing something? Mike. Query 1 EXEC sp_executesql N'SELECT FirstName, LastName, Company, StreetAddress, City, State, ZIP5, ZIP4 FROM Customers WHERE City = @P1 AND State = @P2', N'@P1 char(32), @P2 varchar(32)', 'Poedunk', 'Iowa' Query 2 DECLARE @P1 varchar(32) DECLARE @P2 varchar(32) SET @P1 = 'Poedunk' SET @P2 = 'Iowa' SELECT FirstName, LastName, Company, StreetAddress, City, State, ZIP5, ZIP4 FROM Customers WHERE City = @P1 AND State = @P2 |
#24
| |||
| |||
|
|
SQL Server 2005 Database Engine Tuning Advisor informs me that I should replace query 1 below with the syntax in query 2 below. I’m just not seeing the reason since both the “SELECT” statements optimization plans are stored for reuse. Am I missing something? Mike. Query 1 EXEC sp_executesql N'SELECT FirstName, LastName, Company, StreetAddress, City, State, ZIP5, ZIP4 FROM Customers WHERE City = @P1 AND State = @P2', N'@P1 char(32), @P2 varchar(32)', 'Poedunk', 'Iowa' Query 2 DECLARE @P1 varchar(32) DECLARE @P2 varchar(32) SET @P1 = 'Poedunk' SET @P2 = 'Iowa' SELECT FirstName, LastName, Company, StreetAddress, City, State, ZIP5, ZIP4 FROM Customers WHERE City = @P1 AND State = @P2 |
#25
| |||
| |||
|
|
SQL Server 2005 Database Engine Tuning Advisor informs me that I should replace query 1 below with the syntax in query 2 below. I’m just not seeing the reason since both the “SELECT” statements optimization plans are stored for reuse. Am I missing something? Mike. Query 1 EXEC sp_executesql N'SELECT FirstName, LastName, Company, StreetAddress, City, State, ZIP5, ZIP4 FROM Customers WHERE City = @P1 AND State = @P2', N'@P1 char(32), @P2 varchar(32)', 'Poedunk', 'Iowa' Query 2 DECLARE @P1 varchar(32) DECLARE @P2 varchar(32) SET @P1 = 'Poedunk' SET @P2 = 'Iowa' SELECT FirstName, LastName, Company, StreetAddress, City, State, ZIP5, ZIP4 FROM Customers WHERE City = @P1 AND State = @P2 |
#26
| |||
| |||
|
|
SQL Server 2005 Database Engine Tuning Advisor informs me that I should replace query 1 below with the syntax in query 2 below. I’m just not seeing the reason since both the “SELECT” statements optimization plans are stored for reuse. Am I missing something? Mike. Query 1 EXEC sp_executesql N'SELECT FirstName, LastName, Company, StreetAddress, City, State, ZIP5, ZIP4 FROM Customers WHERE City = @P1 AND State = @P2', N'@P1 char(32), @P2 varchar(32)', 'Poedunk', 'Iowa' Query 2 DECLARE @P1 varchar(32) DECLARE @P2 varchar(32) SET @P1 = 'Poedunk' SET @P2 = 'Iowa' SELECT FirstName, LastName, Company, StreetAddress, City, State, ZIP5, ZIP4 FROM Customers WHERE City = @P1 AND State = @P2 |
#27
| |||
| |||
|
|
SQL Server 2005 Database Engine Tuning Advisor informs me that I should replace query 1 below with the syntax in query 2 below. I’m just not seeing the reason since both the “SELECT” statements optimization plans are stored for reuse. Am I missing something? Mike. Query 1 EXEC sp_executesql N'SELECT FirstName, LastName, Company, StreetAddress, City, State, ZIP5, ZIP4 FROM Customers WHERE City = @P1 AND State = @P2', N'@P1 char(32), @P2 varchar(32)', 'Poedunk', 'Iowa' Query 2 DECLARE @P1 varchar(32) DECLARE @P2 varchar(32) SET @P1 = 'Poedunk' SET @P2 = 'Iowa' SELECT FirstName, LastName, Company, StreetAddress, City, State, ZIP5, ZIP4 FROM Customers WHERE City = @P1 AND State = @P2 |
#28
| |||
| |||
|
|
SQL Server 2005 Database Engine Tuning Advisor informs me that I should replace query 1 below with the syntax in query 2 below. I’m just not seeing the reason since both the “SELECT” statements optimization plans are stored for reuse. Am I missing something? Mike. Query 1 EXEC sp_executesql N'SELECT FirstName, LastName, Company, StreetAddress, City, State, ZIP5, ZIP4 FROM Customers WHERE City = @P1 AND State = @P2', N'@P1 char(32), @P2 varchar(32)', 'Poedunk', 'Iowa' Query 2 DECLARE @P1 varchar(32) DECLARE @P2 varchar(32) SET @P1 = 'Poedunk' SET @P2 = 'Iowa' SELECT FirstName, LastName, Company, StreetAddress, City, State, ZIP5, ZIP4 FROM Customers WHERE City = @P1 AND State = @P2 |
#29
| |||
| |||
|
|
Mike (mssql (AT) nospam (DOT) nospam) writes: SQL Server 2005 Database Engine Tuning Advisor informs me that I should replace query 1 below with the syntax in query 2 below. I’m just not seeing the reason since both the “SELECT” statements optimization plans are stored for reuse. Am I missing something? Mike. Query 1 EXEC sp_executesql N'SELECT FirstName, LastName, Company, StreetAddress, City, State, ZIP5, ZIP4 FROM Customers WHERE City = @P1 AND State = @P2', N'@P1 char(32), @P2 varchar(32)', 'Poedunk', 'Iowa' Query 2 DECLARE @P1 varchar(32) DECLARE @P2 varchar(32) SET @P1 = 'Poedunk' SET @P2 = 'Iowa' SELECT FirstName, LastName, Company, StreetAddress, City, State, ZIP5, ZIP4 FROM Customers WHERE City = @P1 AND State = @P2 Russell seemed to assumed that query 2 is a stored procedure. I may be missing something, but I cannot see any SP. And as a loose query batch, it's a poor choice. If you change the parameter values, it will be a new query text, and there will be no cache it. On top of that, since SQL Server does not know the parameter values, it will not "sniff" the parameters on the first invocation but make some standard assumption. -- Erland Sommarskog, SQL Server MVP, esquel (AT) sommarskog (DOT) se Links for SQL Server Books Online: SQL 2008: http://msdn.microsoft.com/en-us/sqlserver/cc514207.aspx SQL 2005: http://msdn.microsoft.com/en-us/sqlserver/bb895970.aspx SQL 2000: http://www.microsoft.com/sql/prodinf...ons/books.mspx |
#30
| |||
| |||
|
|
Mike (mssql (AT) nospam (DOT) nospam) writes: SQL Server 2005 Database Engine Tuning Advisor informs me that I should replace query 1 below with the syntax in query 2 below. I’m just not seeing the reason since both the “SELECT” statements optimization plans are stored for reuse. Am I missing something? Mike. Query 1 EXEC sp_executesql N'SELECT FirstName, LastName, Company, StreetAddress, City, State, ZIP5, ZIP4 FROM Customers WHERE City = @P1 AND State = @P2', N'@P1 char(32), @P2 varchar(32)', 'Poedunk', 'Iowa' Query 2 DECLARE @P1 varchar(32) DECLARE @P2 varchar(32) SET @P1 = 'Poedunk' SET @P2 = 'Iowa' SELECT FirstName, LastName, Company, StreetAddress, City, State, ZIP5, ZIP4 FROM Customers WHERE City = @P1 AND State = @P2 Russell seemed to assumed that query 2 is a stored procedure. I may be missing something, but I cannot see any SP. And as a loose query batch, it's a poor choice. If you change the parameter values, it will be a new query text, and there will be no cache it. On top of that, since SQL Server does not know the parameter values, it will not "sniff" the parameters on the first invocation but make some standard assumption. -- Erland Sommarskog, SQL Server MVP, esquel (AT) sommarskog (DOT) se Links for SQL Server Books Online: SQL 2008: http://msdn.microsoft.com/en-us/sqlserver/cc514207.aspx SQL 2005: http://msdn.microsoft.com/en-us/sqlserver/bb895970.aspx SQL 2000: http://www.microsoft.com/sql/prodinf...ons/books.mspx |
![]() |
| Thread Tools | |
| Display Modes | |
| |