select * from sampleTable
where
case when @taxtype = 'P' then
(taxtype = 'P' or (taxtype = 'E' and code in ('MER','SER')))
Else
(taxtype = 'E' and code not in ('MER','SER'))
end
Ser ud dette vil fungere med Postres
Rediger:
Forlader mit oprindelige svar, fordi hovedindholdet virker, men Postgres har ikke et koncept med variabler ligesom andre RDBMS'er, så jeg omskrev dette som
WITH myconstants as (SELECT 'P'::text as vtaxtype)
select * from sampleTable
where
case when (select vTaxType from myconstants) = 'P' then
(taxtype = 'P' or (taxtype = 'E' and code in ('MER','SER')))
Else
(taxtype = 'E' and code not in ('MER','SER'))
end;
Her er en SQL Fiddle viser det