Recently have designed a SSRS report for CRM 2011 on-premise using the @CRM_EntityName parameters to enable the Prefiltering option. But for some strange reason when I choose any value on the prefiltering window the report exits with an exception. Then I created a SQL Profiler and this is what the SQL receive:
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'
When I run this statement directly on SQL I receive the following error:
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'.
If I change the aliases given by CRM to the select statements defined in the parameters works without problems.
I dont know what could be the problem.