Friday, March 23, 2012

Index Problem

I have a clustered index (columns a and b) on a table that is used when
running the SQL
Select a,b,c from table where a='test' and b='test1'
However when running the sql
exec sp_executesql 'Select a,b,c from atable where a=@.p1 and b=@.p2', '@.p1'
,'@.p2'.'test','test1'
an index scan is used on the primary key which is not one of the above
columns.
My application server packages sql up as the second option.
Any ideas why the clustered index is not being used for the second option.
TIA Paul"news.microsoft.com" <P@.cookson_remove_.demon.co.uk> wrote in message
news:efvsqK8qEHA.376@.TK2MSFTNGP14.phx.gbl...
> I have a clustered index (columns a and b) on a table that is used when
> running the SQL
> Select a,b,c from table where a='test' and b='test1'
> However when running the sql
> exec sp_executesql 'Select a,b,c from atable where a=@.p1 and b=@.p2', '@.p1'
> ,'@.p2'.'test','test1'
> an index scan is used on the primary key which is not one of the above
> columns.
> My application server packages sql up as the second option.
> Any ideas why the clustered index is not being used for the second option.
> TIA Paul
>
The application server was putting it as the wrong data type nvarchar(5000)
and hence the index was not being used.
regards Paul (changed username this time)

No comments:

Post a Comment