我的应用程序中有过滤器,必须转换为SQL服务器语法。
COLUMN1 in (
if {?Param} = "VALUE1" then 'V1'
else if {?Param} = "VALUE2" then 'V2'
else if {?Param} = "VALUE1 AND VALUE2" THEN 'V1,V2'
)
前两个条件可以用case检查,但最后一个条件是错误,因为必须检查多个值。
任何人都可以指导如何在SQL Server的where子句中添加此条件。
答案 0 :(得分:1)
WHERE (@Param = 'VALUE1' AND COLUMN1 = 'V1')
OR (@Param = 'VALUE2' AND COLUMN1 = 'V2')
OR (@Param = 'VALUE1 AND VALUE2' AND COLUMN1 IN ('V1', 'V2'))
或:
WHERE
COLUMN1 = CASE @Param
WHEN 'VALUE1' THEN 'V1'
WHEN 'VALUE2' THEN 'V2'
END
OR (@Param = 'VALUE1 AND VALUE2' AND COLUMN1 IN ('V1', 'V2'))