关于SQL效率问题,高手来帮忙

hailang3275 2006-06-20 04:28:31
要写一个察看部门事务的SQL语句:
1、解决部门等于该用户的部门,且该用户是部门经理或有权限察看部门事务的人(or)
2、发起部门等于该用户的部门,且该用户是部门经理或有权限察看部门事务的人(or)
3、发起人 解决人不等于该用户(等于的属于个人事务)(and)
4、事务处理明细中的解决部门是该用户的部门(or)
5、事务处理明细中的解决人是该用户的(or)
具体的语句如下,现在的问题是效率太低,造成超时(30秒)

select @conditionText = ' WHERE 1=1 ' + @Condition
+' AND (( ( '
+'((a.resolve_department ='+''''+@dempartment+''''+' or a.origin_department='+''''+@dempartment+'''' +') and '+''''+@EmployeeID+''''+ ' in ( select managerid from Wygl_Office_Department where departmentid= '+''''+@dempartment+''''+'))'
+'or ((a.resolve_department ='+''''+@dempartment +''''+'or a.origin_department='+''''+@dempartment+''''+') and ( '+''''+@EmployeeID+''''+' IN ( select EmployeeID from Wygl_System_UserAuthorization where Especially LIKE ''%M%'' )))'
+' ) '
+ ' AND a.origin_employee <> '+''''+@EmployeeID+''''
+ ' AND a.resolve_employee <> '+''''+@EmployeeID+''''+')'
+ ' OR ( A.request_id in (select request_id from wygl_manager_progressdetail where origin_department = '+''''+@dempartment+''''+' ) )'
+ ' OR ( A.request_id in (select request_id from wygl_manager_progressdetail where origin_Employee = '+''''+@EmployeeID+''''+' ) ) )'
+' ORDER BY A.request_id DESC '
...全文
118 4 打赏 收藏 转发到动态 举报
写回复
用AI写文章
4 条回复
切换为时间正序
请发表友善的回复…
发表回复
hailang3275 2006-06-21
  • 打赏
  • 举报
回复
暂时解决了
谢谢
itblog 2006-06-20
  • 打赏
  • 举报
回复
帮顶,学习一下!
hailang3275 2006-06-20
  • 打赏
  • 举报
回复
但是业务逻辑是要需要的
表结构改也来不及了
有没有好的替代方法?
LouisXIV 2006-06-20
  • 打赏
  • 举报
回复
^^;

or and in like那么多,效率肯定上不去

34,590

社区成员

发帖
与我相关
我的任务
社区描述
MS-SQL Server相关内容讨论专区
社区管理员
  • 基础类社区
  • 二月十六
  • 卖水果的net
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧