我正在尝试修改报告,我需要根据一列中的数据排除多行,该列的表达式为:
=iif(sum(iif(left(Fields!crs_group.Value,1) = "G",1,0)
,"GrpCourse")=0,"n/a",
sum(iif(Fields!crs_group.Value="Enrolled on Course",1,0))
- sum(iif(left(Fields!crs_group.Value,1) = "G",1,0)))
我想如果我可以将它转换为 SQL,我可以过滤掉查询中的那些行。到目前为止,我的代码是:
CASE WHEN SUM(CASE WHEN LEFT(sub.crs_group, 1) = 'G'
THEN 1 ELSE 0 END)=0 THEN 999999999
ELSE SUM(CASE WHEN sub.crs_group = 'Enrolled on Course'
THEN 1 ELSE 0 END) - SUM(CASE WHEN LEFT(sub.crs_group,1) = 'G'
THEN 1 ELSE 0 END)
END AS NumberNotInGroups
但是,这不会在报告运行时给出匹配的结果。我已将“n/a”更改为 999999999,因为我得到了从 VARCHAR 到 INT 的转换错误。我尝试转换为 VARCHAR 但没有成功。任何帮助将不胜感激,昨天整个下午都在试图弄清楚。
编辑
这是完整的查询:
SELECT
sub.course,
sub.crs_group,
m.m_reference,
me.e_status,
me.e_id,
s.s_studentreference,
p.p_forenames,
p.p_surname,
pcd.p_surname + ',' + pcd.p_forenames as course_dir,
CASE WHEN SUM(CASE WHEN LEFT(sub.crs_group, 1) = 'G' THEN 1 ELSE 0 END)=0 THEN 999999999
ELSE SUM(CASE WHEN sub.crs_group = 'Enrolled on Course' THEN 1 ELSE 0 END) - SUM(CASE WHEN LEFT(sub.crs_group,1) = 'G' THEN 1 ELSE 0 END)
END AS NumberNotInGroups
FROM
msql.unitesnapshot.dbo.capd_moduleenrolment AS me
INNER JOIN msql.unitesnapshot.dbo.capd_module AS m ON me.e_module = m.m_id
LEFT JOIN msql.unitesnapshot.dbo.capd_staff scd on m.m_modulesupervisor = scd.s_id
LEFT JOIN msql.unitesnapshot.dbo.capd_person pcd on scd.s_id = pcd.p_id
INNER JOIN msql.unitesnapshot.dbo.capd_student s on me.e_student = s.s_id
INNER JOIN msql.unitesnapshot.dbo.capd_person p on s.s_id = p.p_id
INNER JOIN (SELECT
m.m_id,
CASE WHEN m.m_reference not like '%G_' THEN m.m_reference ELSE LEFT(m.m_reference, charindex('G', m.m_reference) - 1) END AS course,
CASE WHEN m.m_reference not like '%G_' THEN 'Enrolled on Course' ELSE RIGHT(m.m_reference, 2) END AS crs_group
FROM
unitesnapshot.dbo.capd_module m) sub ON sub.m_id = me.e_module
WHERE
me.e_status = 'A' AND
LEFT(m.m_reference, 2) = '12' AND
SUBSTRING(m.m_reference, 7, 2) in ('VF','AB','FB')
GROUP BY
sub.course,
sub.crs_group,
m.m_reference,
me.e_status,
me.e_id,
s.s_studentreference,
p.p_forenames,
p.p_surname,
pcd.p_surname + ',' + pcd.p_forenames
ORDER BY
p.p_surname
这是 SSRS 中的正确结果:
这是 sql-server 中的错误结果,它应该显示 1 而不是 99999999: