I don't get what %1 is. Is that supposed to be a string format location?As a WAG, I'd say you need to replace %1 with a variable. Here is a sample with data in a consumable format:DECLARE @Foo TABLE (ID INT, DefID INT, AttrID INT, version INT, Valstr VARCHAR(100))INSERT @FooVALUES(123, 475909, 2, 1, 'test'),(123, 475909, 2, 2, 'test1'),(123, 475909, 2, 2, 'test3'),(345, 475806, 5, 1, 'test'),(345, 475806, 5, 2, 'test')DECLARE @Bar VARCHAR(100)SET @Bar = 'test'SELECT MAX(VALSTR)FROM @FooWHERE AttrID = 2 AND DefID = 475909 AND (Valstr like '%' + @Bar + '%' OR @Bar IS NULL)