I thought this might be an easy question to answer but after hours of searching the web, I'm giving up.
I have a SQL 2005 table with a few composite indexes and a few single column indexes. I've narrowed my problem down to this; if I run a query such as the following:
select * from tbl
where col = 'test'
the execution plan shows that index built on col is used. However if I run the query this way:
declare @var varchar(10)
set @var = 'test'
select * from tbl
where col = @var
then the execution plan shows that the index wasn't used.
I would like to know if this is how sql works or is the sql optimizer just recognizing that it doesn't need to use the index.
Thanks in advance for your help, Z