WHERE Something IN (CASE WHEN statement)?(WHERE 东西在(CASE WHEN 语句)?)
本文介绍了WHERE 东西在(CASE WHEN 语句)?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我想根据条件写一个select子句"!但我有错误:
I want to write a "select clause" according to conditional condition!
bu I have error:
Msg 512, Level 16, State 1, Line 2
Subquery returned more than 1 value. This is not permitted when the subquery follows =, !=, <, <= , >, >= or when the subquery is used as an expression.
我该如何解决??
这是我的简化代码:
How can I fix it??
here is my simplified code:
SELECT UnitsAllocation.UnitID
, OrganizationUnits.Title AS UnitTitle
, 'Title' AS ExpenseTitle1
, SUM(UnitsAllocationDetails1.ExpenseAmount1) AS ExpenseAmount1
FROM [bdg_UnitsAllocation] UnitsAllocation
LEFT OUTER JOIN (
SELECT UnitsAllocationDetails.UnitsAllocationID
, SUM(UnitsAllocationDetails.Amount) / 1 AS ExpenseAmount1
FROM [bdg_UnitsAllocationDetails] UnitsAllocationDetails
WHERE UnitsAllocationDetails.ExpenseID IN (
CASE 1 WHEN 1
THEN ( SELECT Id FROM bdg_Expenses WHERE ParentId = 1 )
ELSE ( SELECT Id FROM bdg_Expenses WHERE Id = 1 )
END
)
GROUP BY
UnitsAllocationDetails.UnitsAllocationID
) UnitsAllocationDetails1 ON UnitsAllocationDetails1.UnitsAllocationID = UnitsAllocation.ID
LEFT OUTER JOIN [bdg_OrganizationUnits] OrganizationUnits ON UnitsAllocation.UnitID = OrganizationUnits.ID
GROUP BY
UnitsAllocation.UnitID, OrganizationUnits.Title
请看CASE"和IN"语句.
推荐答案
为什么要使用案例?你不能就这样
why use a case? can't you just do
where (@Level = 1 and ExpenseId in (select id from bdg_expenses where parentid = 1)) or
(@Level <> 1 and ExpenseId in (select id from bdg_expenses where id = 1))
这篇关于WHERE 东西在(CASE WHEN 语句)?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持编程学习网!
沃梦达教程
本文标题为:WHERE 东西在(CASE WHEN 语句)?


猜你喜欢
- 如何将 Byte[] 插入 SQL Server VARBINARY 列 2021-01-01
- 远程 mySQL 连接抛出“无法使用旧的不安全身份验证连接到 MySQL 4.1+"来自 XAMPP 的错误 2022-01-01
- 在SQL中,如何为每个组选择前2行 2021-01-01
- 更改自动增量起始编号? 2021-01-01
- 使用 Oracle PL/SQL developer 生成测试数据 2021-01-01
- 以一个值为轴心,但将一行上的数据按另一行分组? 2022-01-01
- SQL 临时表问题 2022-01-01
- 如何将 SonarQube 6.7 从 MySQL 迁移到 postgresql 2022-01-01
- 如何使用 pip 安装 Python MySQLdb 模块? 2021-01-01
- 导入具有可变标题的 Excel 文件 2021-01-01