<an******@gmail.com> wrote in message
news:11**********************@f14g2000cwb.googlegr oups.com...
Is it possible to force the use of a compound index in a query?
create table Test (ColOne int, ColTwo int)
The compound index is ColOne + ColTwo.
I'm interested in searching on ColTwo, but I also know the value of
ColOne will always be the number "1".
How do you structure the SQL statement to concatenate the two INTs and
use the index? Note that I don't have any control over the creation of
these indexes.
I don't really understand what you mean - what does "concatenating INTs"
mean? Do you mean you have a computed column which is the sum of ColOne and
ColTwo? Or a computed column which does string concatenation of the values
in ColOne and ColTwo? And if ColOne is always 1, why do you even need it in
the table?
Assuming ColOne is always 1, and you search for values in ColTwo, then there
doesn't seem to be much point in indexing ColOne (unless it's part of a key
or constraint which you haven't mentioned), so I would just index ColTwo. If
you really do need a composite index on those columns, then you can change
the order of the columns in the index, and build it on (ColTwo, ColOne)
instead.
If this doesn't help, I suggest you post your CREATE INDEX or ALTER TABLE
.... ADD CONSTRAINT ... statements to make it clear exactly what you're
doing.
Simon