performance with dynamic variable... -
03-27-2006
, 11:19 PM
Sybase 12.x on Linux. I am relatively new to Sybase.
I have a query q1 ( as part of a stored proc ):
declare @accountId int
set @accountId = 100
select col1, col2 from MyTable where accountId = @accountId
There is an index on "accountId". But this index is not used. Whereas it is
used in the query ( q2 ) below:
declare @accountId int
set @accountId = 100
declare @sqlSel varchar(1000)
set sqlSel = "select col1, col2 from MyTable where accountId = " +
@accountId
exec (@sqlSel)
I can see why the index is used in q2. But in q1, the optimizer knows that
"@accountId" has been declared as int - still it does not try to use the
index.
Is there anyway this can be solved ?
Thanks
-- padhu |