I'm using SQL Server 2005.
I have a problems with executing SQL statements like this
DECLARE @Param1 BIT
SET @Param1 = 1
SELECT
t1.Col1,
t1.Col2
FROM
Table1 t1
WHERE
@Param1=0 OR
(t1.Col2 in
(SELECT t2.Col4
FROM
Table2 t2
WHERE
t2.Col1 = t1.Col1 AND
t2.Col2 = 'AAA' AND
t2.t3 <> 0)
)
This query executes very long time.
But if I replace @Param1 with 1, than query execution time is ~2 seconds.
Any information how to resolve the problem would be greatly appreciated.