如何在where子句中使用语句 [英] How to use statements in where clause

查看:120
本文介绍了如何在where子句中使用语句的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

实际上我想做的是......如果我的角色名是HR,那么我想显示所有角色的信息(小时,经理,员工和管理员)
如果我的角色名是经理,那么我想显示(员工和经理)的信息

如果其员工再次只有经理和员工





i我在我的where子句中尝试这个但没有工作

其中......

和(@ RoleName ='员工'和r.Name in('Employee','Manager')

或(@ RoleName ='Manager'和r.Name in('Employee','Manager')
$'b $ b或r.Name in('HR','Manager','Employee','MasterAdmin'))

解决方案

你的方法还可以 - 它是可能只是一个小语法的东西(假设您的表,列名都在位等)。

应该没有问题,正如ryanb31建议的那样,使用(和)来正确定义SQL部分。



你能做什么为了解析你的SQL查询是迭代地添加部分并查看哪一个得到错误的结果,在像你的例子这样的小查询中应该很容易解决。



祝你好运,

Edo


hii ,
actually what i want to do is .. if my role name is HR then i want to display information regarding of all roles (hr,manager,employee and admin)
if my rolename is manager then i want to display information of (employee and manager)
if its employee then again only manager and employee


i am trying this in my where clause but not working
where ...
and (@RoleName='Employee' And r.Name in('Employee','Manager')
or (@RoleName='Manager' And r.Name in('Employee','Manager'))
or r.Name in ('HR','Manager','Employee','MasterAdmin'))

解决方案

Your approach is ok - it's probably just a small syntax thing (provided that your tables, col names all are in place etc).
there shouldn't be a problem, as ryanb31 suggested, use ( and ) to define SQL parts properly.

What you can do in order to "parse" your SQL query is to add parts iteratively and see in which one get wrong results, in small queries like your example is should work out pretty easily.

Good luck,
Edo


这篇关于如何在where子句中使用语句的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆