I was wondering if there was a way to not execute my subquery if my @ID1 is NULL?
CREATE PROCEDURE [dbo].[TestTable_Search]
@Col1 int,
@Col2 uniqueidentifier,
@Col3 datetime,
@Col4 datetime,
@ID1 varchar(10)
AS
SET TRANSACTION ISOLATION LEVEL READ COMMITTED
SELECT *
FROM
[dbo].[TestTable]
WHERE
[Col1] = COALESCE(@Col1, Col1) AND
[Col2] = COALESCE(@Col2, Col2) AND
[Col3] >= COALESCE(@Col3 + "00:00:00", Col3) AND
[Col4] <= COALESCE(@Col4 + "23:59:59", Col4) AND
[Col5] IN (SELECT [ID2] FROM [dbo].[TestTable2] WHERE [ID1] = @ID1)