How about:...?
set @companyname = 'A%'
set @companynameOp = 'ne'
set @country = 'Germany'
set @countryOp = 'eq'
set@companyName =
case @companyNameOp
when '' then null
when 'eq' then -- Operator is "equals"
@companyName
when 'bg' then -- Operator is "begins with"
@companyName +'%'
when 'ed' then -- Operator is "ends with"
'%' + @companyName
when 'ct' then -- Operator is "contains"
'%' + @companyName + '%'
set@country =
case @countryOp
when '' then null
when 'eq' then -- Operator is "equals"
@country
when 'bg' then -- Operator is "begins with"
@country +'%'
when 'ed' then -- Operator is "ends with"
'%' + @country
when 'ct' then -- Operator is "contains"
'%' + @country + '%'
-- Ok, now let's form our query.
select
customerid, companyname, country
from
customers
where
(companyName like @companyName or @companyName is null)
AND
(country like @country or @country is null)