[英]Missing expression error in Select subquery in Case expression
I have to write a SQL with Case expression joining many tables to retrieve 2 fields , which will populate another table B. 我必须编写一个带有Case表达式的SQL,该表达式连接许多表以检索2个字段,这将填充另一个表B。
Below is some of my case conditions: 以下是我的一些案例条件:
CASE
A_FLG = 'Y' and Mod code = 'P' and Year(T_DT) < 2011
set GRP_ID = 2
Colum TDR_DT is derived from other table C. I compiled my SQL as follows: Colum TDR_DT是从其他表C派生的。我将SQL编译如下:
Select
case
when A.A_FLG = 'Y' and C.MCODE ='P'
and (
select extract(year from C.T_DT) from Table C where
extract(year from C.T_DT)
)<2010
then '2'
else '-1'
END "GRP_ID",
from Table A
join Table F
on A.ID=F.ID
On executing the query, I find error "Missing expression" pointing at first Case . 在执行查询时,我发现指向第一个Case的错误“Missing expression”。 I have tried to figure out what could be the error, but am unable to do so.
我试图找出可能的错误,但无法做到这一点。 ANy help is deeply appreciated, since I have many more case statements to write and this is holding up my work.
非常感谢您的帮助,因为我还有很多案例要写,这阻碍了我的工作。
You are not given any relation between the table A
, B
and C
so I am assuming there are no relation. 表
A
, B
和C
之间没有任何关系,所以我假设没有关系。 And you want to access the MCODE
from the C
table in your expression so you can fire up another subquery for that, 并且您希望从表达式中的
C
表访问MCODE
,以便为此启动另一个子查询,
Select
case when A.A_FLG = 'Y'
and (Select TOP 1 C.MCODE from tablec C Where yourcondition =value) ='P'
and (select extract(year from C.T_DT) from Table C where extract(year from C.T_DT))<2010
then '2'
else '-1'
END "GRP_ID",
from Table A
join Table F
on A.ID=F.ID
I am selecting the Top 1
because you need to make sure the select statement will always returns the one value for each join row. 我选择
Top 1
是因为您需要确保select语句将始终返回每个连接行的一个值。 You can remove it if you no for sure that your condition are going to always return single row. 如果没有,则可以将其删除,以确保您的条件将始终返回单行。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.