在预过滤Windows中选择值时出错

时间:2014-02-12 16:41:58

标签: sql-server-2008 reporting-services dynamics-crm-2011

最近,我们使用@CRM_EntityName参数为CRM 2011内部部署设计了SSRS报告,以启用Prefiltering选项。但是由于某些奇怪的原因,当我在预过滤窗口中选择任何值时,报告会以异常退出。然后我创建了一个SQL Profiler,这就是SQL收到的内容:

    exec sp_executesql N'declare @binUserGuid varbinary(128)
                                            declare @userGuid uniqueidentifier
                                            select @userGuid = N''{552d241b-0347-e311-9f1e-00155d039706}''
                                            set @binUserGuid = cast(@userGuid as varbinary(128))
                                            set context_info @binUserGuid;

                                            DECLARE @SQL2 AS nVarchar(max)
    SET                @SQL2 = ''SELECT StudentsRecords.xrmsm_students_id, StudentsRecords.xrmsm_studentsfullname, StudentProgress.TotalPoints, StudentProgress.PointsObtained, 
                             StudentProgress.xrmsm_subjectscode, StudentProgress.Average, 
                             CASE WHEN StudentProgress.Average >= 90 THEN ''''AN'''' WHEN StudentProgress.Average >= 80 THEN ''''PR'''' WHEN StudentProgress.Average >= 60 THEN ''''EP'''' WHEN StudentProgress.Average
                          > - 1 THEN ''''I'''' ELSE NULL END AS Progress, CONVERT(nvarchar(50), StudentsRecords.xrmsm_studentsid) + StudentProgress.xrmsm_subjectscode AS VLookupData, 
                         StudentsRecords.xrmsm_studentsgrade, StudentsRecords.xrmsm_studentsgradename as Value
FROM            Filteredxrmsm_students AS StudentsRecords INNER JOIN
                             (SELECT st.xrmsm_studentsid, su.xrmsm_subjectscode, 
                                                         SUM(sc.xrmsm_scoresresults) AS PointsObtained, SUM(eva.xrmsm_evaluationstotal) AS TotalPoints, 
                                                         SUM(sc.xrmsm_scoresresults) / SUM(eva.xrmsm_evaluationstotal) * 100.00 AS Average
                               FROM            Filteredxrmsm_scores as sc INNER JOIN
                                                         Filteredxrmsm_evaluations as eva ON sc.xrmsm_evaluationlookup = eva.xrmsm_evaluationsid INNER JOIN
                                                         Filteredxrmsm_students as st ON sc.xrmsm_studentlookup = st.xrmsm_studentsid INNER JOIN 
                                                         (''
                          + @CRM_Filteredxrmsm_sessions + '')
                                                          AS se ON 
                                                         se.xrmsm_sessionsid = eva.xrmsm_sessionlookup INNER JOIN
                                                         Filteredxrmsm_institutionCourses as ic ON 
                                                         ic.xrmsm_institutioncoursesid = se.xrmsm_institutioncourselookup INNER JOIN
                                                         Filteredxrmsm_courses as co ON co.xrmsm_coursesid = ic.xrmsm_courselookup INNER JOIN
                                                         (''
                          + @CRM_Filteredxrmsm_subjects + '') AS su ON 
                                                         su.xrmsm_subjectsid = co.xrmsm_subjectlookup INNER JOIN
                                                         Filteredxrmsm_sessionEnrollments as sen ON sen.xrmsm_studentlookup = sc.xrmsm_studentlookup AND
                                                          eva.xrmsm_sessionlookup = se.xrmsm_sessionsid AND 
                                                         eva.xrmsm_termsessionlookup = sen.xrmsm_termsessionlookup INNER JOIN 
                                                         (''
                          + @CRM_Filteredxrmsm_educationalstructure + '') as ed ON 
                                                         eva.xrmsm_yearlookup = ed.xrmsm_yearlookup AND 
                                                         se.xrmsm_institutionlookup = ed.xrmsm_institutionlookup AND 
                                                         ed.xrmsm_programlookup = se.xrmsm_programlookup 
                               WHERE        (eva.xrmsm_evaluationsdate >= ''''''+ convert(varchar(10),@termStartDate,120) + '''''') AND (eva.xrmsm_evaluationsdate <= ''''''+ convert(varchar(10),@monthReport,120) + '''''')
                                                          AND (eva.statuscode = 1) AND (sc.statuscode = 1) AND (st.statuscode = 1) AND 
                                                         (se.statuscode = 1) AND (sen.statuscode = 1) AND 
                                                         (ed.statuscode = 1)
                               GROUP BY st.xrmsm_studentsid, su.xrmsm_subjectscode) AS StudentProgress ON 
                         StudentsRecords.xrmsm_studentsid = StudentProgress.xrmsm_studentsid''
                          EXEC (@SQL2)',N'@CRM_Filteredxrmsm_educationalstructure nvarchar(114),@CRM_Filteredxrmsm_sessions nvarchar(78),@CRM_Filteredxrmsm_subjects nvarchar(165),@termStartDate datetime,@monthReport datetime',@CRM_Filteredxrmsm_educationalstructure=N'select 
[xrmsm_educationalstructure0].* 
from
 Filteredxrmsm_educationalstructure as "xrmsm_educationalstructure0"',@CRM_Filteredxrmsm_sessions=N'select 
[xrmsm_sessions0].* 
from
 Filteredxrmsm_sessions as "xrmsm_sessions0"',@CRM_Filteredxrmsm_subjects=N'select 
[xrmsm_subjects0].* 
from
 Filteredxrmsm_subjects as "xrmsm_subjects0" 
where
 ("xrmsm_subjects0".xrmsm_subjectsid = N''0FE2990A-1847-E311-9F1E-00155D039706'')',@termStartDate='2014-01-01 00:00:00',@monthReport='2014-01-31 00:00:00'

当我直接在SQL上运行此语句时,我收到以下错误:

Msg 4145, Level 15, State 1, Line 44
An expression of non-boolean type specified in a context where a condition is expected, near 'Student'.

我不知道可能是什么问题。

1 个答案:

答案 0 :(得分:0)

感谢所有观点。我已经解决了这个问题。我的解决方案是使用子查询部分生成数据集,然后在报告中进行计算。