0

我在下面设置了一个案例语句,查看学生年(stuyear)(最终将由 asp.net 控件触发。该案例设置为在将结果输出到三列时将其包含在计算中。但是,如果我将stuyearwithin的值maindata从 11 更改为 10,如下面的输出列返回 0。该语句似乎只对前三种情况有效,然后最后六个它返回 0,就好像它们被忽略了一样。

我想要发生的是stuyearbelowexpected,asexpectedaboveexpected.

如果可以避免的话,我不想为第 9 年、第 10 年和第 11 年设置单独的列并触发它们在 VB.net 中的可见性。

/*Progress*/您可以在下面的示例中的注释下找到我所指的特定代码。

;with MainData as 
(
select surname, forename, stuyear, ks2en, result, case when ks2en='' then 5 else left(ks2en,1) end as ks2enlevel, value as ResultLevel, case when ks2en='' then 0 else 1 end as gotks2enlevel 
from student join subject on student.upn=subject.upn join gradelookup on subject.result=gradelookup.grade where datacollection='March 2013' and stuyear=10 and name = 'English'
),

calcproglevel as
(
Select surname, forename, stuyear, ks2en, result, ks2enlevel, ResultLevel, gotks2enlevel, ResultLevel-ks2enlevel as levelsofprogress from MainData
),

calcprogtotals as
(
select surname, forename, stuyear, ks2en, result, ks2enlevel, ResultLevel, gotks2enlevel, levelsofprogress,
case when ks2enlevel >=4 then 1 else 0 end as AStarCTar,
case when resultlevel >=7 then 1 else 0 end as AStarC

From calcproglevel
)

select surname, forename, stuyear, ks2en, result, ks2enlevel, ResultLevel, gotks2enlevel, AStarCTar, AStarC, levelsofprogress, 

/*Progress*/

/*Year 11 Levels of Porgress below, as and above expected*/
case when stuyear=11 and levelsofprogress < 3 then 1 else 0 end as belowexpected,
case when stuyear=11 and levelsofprogress >= 3 then 1 else 0 end as asexpected,
case when stuyear=11 and levelsofprogress >= 4 then 1 else 0 end as aboveexpected,

/*Year 10 Levels of Porgress below, as and above expected*/
case when stuyear=10 and levelsofprogress < 2 then 1 else 0 end as belowexpected,
case when stuyear=10 and levelsofprogress >= 2 then 1 else 0 end as asexpected,
case when stuyear=10 and levelsofprogress >= 3 then 1 else 0 end as aboveexpected,

/*Year 9 Levels of Porgress below, as and above expected*/
case when stuyear=9 and levelsofprogress < 1 then 1 else 0 end as belowexpected,
case when stuyear=9 and levelsofprogress >= 1 then 1 else 0 end as asexpected,
case when stuyear=9 and levelsofprogress >= 2 then 1 else 0 end as aboveexpected,

/*KS4 individual levels of progress from 0 or less through to 5 levels or greater */
case when (stuyear=9 or stuyear=10 or stuyear=11) and levelsofprogress <= 0 then 1 else 0 end as zeroorless,
case when (stuyear=9 or stuyear=10 or stuyear=11) and levelsofprogress = 1 then 1 else 0 end as onelevelprog,
case when (stuyear=9 or stuyear=10 or stuyear=11) and levelsofprogress = 2 then 1 else 0 end as twolevelprog,
case when (stuyear=9 or stuyear=10 or stuyear=11) and levelsofprogress = 3 then 1 else 0 end as threelevelprog,
case when (stuyear=9 or stuyear=10 or stuyear=11) and levelsofprogress = 4 then 1 else 0 end as fourlevelprog,
case when (stuyear=9 or stuyear=10 or stuyear=11) and levelsofprogress >= 5 then 1 else 0 end as fiveormore


From calcprogtotals
4

1 回答 1

0

我已经整理好了。只需要重新排列和介绍或操作符如下:

case when (stuyear=11 and levelsofprogress < 3)

or

(stuyear=10 and levelsofprogress < 2)

or

(stuyear=9 and levelsofprogress < 1)

then 1 else 0 end as belowexpected,
于 2013-04-11T13:10:36.620 回答