Since you didn't provide and DDL, DML or expected output we can only guess at what your scheam and data might look like. Took a guess at one way you could do this:DECLARE @T TABLE (ID INT IDENTITY(1,1), ConfirmationNumber VARCHAR(10))INSERT @T VALUES('ABCD'),('1234'),(''),('ACC'),('DD4T'),('DD4'),('KKI89'),(''),('0987')DECLARE @ConfirmationNumber VARCHAR(10)SET @ConfirmationNumber = ''SET @ConfirmationNumber = '0'SET @ConfirmationNumber = NULLSELECT *FROM @TWHERE @ConfirmationNumber IS NULL OR ( @ConfirmationNumber = '' AND ConfirmationNumber = '' ) OR ( @ConfirmationNumber <> '' AND ConfirmationNumber LIKE '%' + @ConfirmationNumber + '%' )