Please start any new threads on our new site at https://forums.sqlteam.com. We've got lots of great SQL Server experts to answer whatever question you can come up with.

 All Forums
 SQL Server 2000 Forums
 SQL Server Development (2000)
 Coalesce function

Author  Topic 

AskSQLTeam
Ask SQLTeam Question

0 Posts

Posted - 2001-04-05 : 01:00:41
Paul writes "This is in regard to the article: Implementing a Dynamic Where Clause.

Given the following table:

Create Table XXX
( Col1 int not null,
Col2 int not null,
Constraint PK_XXX Primary Key Custered (Col1, Col2)
)

The table has 20 million rows.

If I select rows where col1 has a given value (say 5) it returns 50 rows in a matter of seconds

The following Proc runs forever:

Create Proc paSelXXX @Col1 int = Null
As
Select *
From XXX
Where Col1 = Coalesce(@Col1, Col1)
Go

I've tried adding an optimiser hint With(Index(0)) to the from clause, but no improvement.

Is there any way to force it to use the index?"
   

- Advertisement -