首页 诗词 字典 板报 句子 名言 友答 励志 学校 网站地图
当前位置: 首页 > 教程频道 > 数据库 > SQL Server >

这个条件语句要怎么写

2012-01-22 
这个条件语句要如何写select*fromduizhaoastmpwhereexists(select*fromduizhaoastmpAwhereexists(select1f

这个条件语句要如何写
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
)
)
)

热点排行