我喜欢在where子句中使用"IF"条件.从各种线程,我理解其中一个选项是CASE表达式,但我无法弄清楚.
示例代码:
select * from sampleTable
where
If @taxtype = 'P' then
(taxtype = 'P' or (taxtype = 'E' and code in ('MER','SER')))
Else
(taxtype = 'E' and code not in ('MER','SER'))
End If
Run Code Online (Sandbox Code Playgroud)
任何帮助是极大的赞赏.
谢谢!