Probably it is because in the parameter case, the optimizer cannot know that the value is not null, so it needs to create a plan that returns correct results even when it is. If you have SQL Server 2008 SP1 you can try adding OPTION(RECOMPILE)
to the query.
More Related Contents:
- Which are more performant, CTE or temporary tables?
- Using merge..output to get mapping between source.id and target.id
- What do Clustered and Non-Clustered index actually mean?
- How to add Active Directory user group as login in SQL Server
- Why use the INCLUDE clause when creating an index?
- How to set a default value for an existing column
- SQL Server pivot vs. multiple join
- LIKE vs CONTAINS on SQL Server
- An attempt was made to access a socket in a way forbidden by its access permissions
- How do I find a stored procedure containing ?
- SQL Server GUID sort algorithm. Why?
- Why is a UDF so much slower than a subquery?
- Does the order of columns in a WHERE clause matter?
- An attempt to login using SQL authentication failed
- SQL Server, the misleading XLOCK & optimizations
- How to create the linked server for SQL Server 2008 where we have the database from 2000 and 2005
- How to find SQL Server running port?
- SQL Server 2008 – How do i return a User-Defined Table Type from a Table-Valued Function?
- Changing SQL Server collation to case insensitive from case sensitive?
- SQL Server SELECT LAST N Rows
- What’s the best way to store co-ordinates (longitude/latitude, from Google Maps) in SQL Server?
- Database design: Calculating the Account Balance
- Which is quicker COALESCE OR ISNULL?
- Instead of trigger in SQL Server loses SCOPE_IDENTITY?
- INFORMATION_SCHEMA vs sysobjects
- Merge multiple rows into a single row
- What are row, page and table locks? And when they are acquired?
- Error converting data types when importing from Excel to SQL Server 2008
- CHECKSUM and CHECKSUM_AGG: What’s the algorithm?
- Implementing one-to-zero-or-one relation in SQL Server