2014-02-12 41 views
0

最近已使用@CRM_EntityName參數設計了用於CRM 2011內部部署的SSRS報告以啓用預過濾選項。但出於某種奇怪的原因,當我在預過濾窗口中選擇任何值時,報告將退出,但有一個例外。然後,我創建了一個SQL事件探查器,這是什麼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'. 

我不知道可能是什麼問題。

回答

0

感謝您的所有意見。我已經解決了這個問題。我的解決方案是使數據集與子查詢部分,然後我在報告中進行計算。