SELECT ReceiptBatchID,ReferenceNumber FROM App.ReceiptBatches WHERE (CASE WHEN isnull(@SearchText,'')<>'' THEN CASE WHEN App.ReceiptBatches.ReceiptBatchID LIKE '%' + @SearchText + '%' THEN 1 WHEN App.ReceiptBatches.ReferenceNumber LIKE '%' + @SearchText + '%' THEN 1 ELSE 0 END ELSE 0 END)=1