这个条件语句要如何写
select * from duizhao as tmp
where exists
(
select * from duizhao as tmpA
where exists
(
select 1 from t_login
where 用户名= 'alibaba ' and charindex(rtrim(tmpA.gsid), 查询范围)> 0
) and zyid = tmp.zyid
)
上面这段是gsid不为空的情况下的写法,还有另一种情况就是gsid为0,则选全部,如果上面所说的情况用条件表达下面的写法问题在哪儿?
where gsid =
(case when 输入参数 in null then gsid else gsid in
(select * from duizhao as tmp
where exists
(
select * from duizhao as tmpA
where exists
(
select 1 from t_login
where 用户名= 'alibaba ' and charindex(rtrim(tmpA.gsid), 查询范围)> 0
) and zyid = tmp.zyid
)
)
)
帮忙改一下吧
------解决方案--------------------where gsid =
(case when 输入参数 in null then gsid else gsid in
(select * from duizhao as tmp
语法错误
------解决方案--------------------where gsid =
(case when 输入参数 in null then gsid else gsid in
(select max(gsid)--指定duizhao表对应的列名(如果结果集有多个时要定义取大或取小的值)
from duizhao as tmp
where exists
(
select * from duizhao as tmpA
where exists
(
select 1 from t_login
where 用户名= 'alibaba ' and charindex(rtrim(tmpA.gsid), 查询范围)> 0
) and zyid = tmp.zyid
)
)
)