我在这里有一个复杂的查询,我在这里嵌套子查询的情况。我无法获得正确的结构。这里是我的代码:使用Subquery Sql语句的嵌套Case语句的正确结构是什么?
select
AccountNo,
Case when Datepart (month,TranDate) = 1 Then
Case ISNULL(RemainingBalance,'NULLVALUE')
When 'NULLVALUE' Then
(select top 1 RemainingBalance From tempAccountBalance
where DATEPART (YEAR,TranDate)[email protected]
order by TranDate desc)
else
MIN(Case when Datepart (month,TranDate) <= 3 Then
RemainingBalance END) End Q1
FROM tempAccountBalance
WHERE Datepart (year,TranDate) = @FiscalYear and [email protected]
Group By AccountNo
我得到它说的错误,Msg 102, Level 15, State 1, Line 11 Incorrect syntax near 'Q1'.
正确缩进或许会更明显地突出了缺失的“END”......你有三个单词“CASE”,只有两个单词“END” - 因此其中一个不会终止。 –