﻿<?xml version="1.0" encoding="utf-8"?>
<ReportsExport>
	<Reports>
		<Report id="d7366764-e2a8-4e09-ba9a-1c091dda6774" codekey="PassedTestsAndWBTs" categoryCodekey="UserStats" name="Bildungshistorie" description="The Report lists all user with all WBTs and Tests they have passed&#xD;&#xA;(WBTs are passed, when a certificate is available for the user or BestComplete is more than the Threshold defined for the WBT)">
			<MetaData created="2012-05-07T18:24:50" modified="2023-12-06T21:36:38" modifiedBy="Administrator_LastName, Administrator_FirstName (Administrator)" modifiedBy_user_id="2" />
			<ExecutionDetails format="TableResult" commandType="SqlCommandOrQuery" exportHandler="" adminControl="" exportMultipleTablesToSheets="False" datesWithTime="False" extraParams="" />
			<Mandators mandatorMode="OnlyOwner" mandator_id="d5a90a49-e697-4aeb-8a5b-298782815490" mandatorName="ELECT" isStandard="False" isUsedByMenu="False" />
			<Roles>
				<Role id="90" />
			</Roles>
			<command>
				-- create temporary table to collect result
				create table #Result (user_id INT, item_id UNIQUEIDENTIFIER)

				-- get "passed" courses
				insert into #Result
				select
				v_Users.intUserCn,
				tblItems.id
				from tblStatusUserCourse
				join tblThemes on tblThemes.id = tblStatusUserCourse.theme_id
				INNER JOIN tblItems ON tblItems.id = tblThemes.id
				join v_Users on v_Users.intUserCn = tblStatusUserCourse.UserId AND v_Users.userStatus &lt;&gt; 2
				-- get courses done by user with result certificate
				where tblItems.deleted IS NULL AND (tblItems.certificate_id is not null
				and dbo.fn_GetUserItemStatus(tblStatusUserCourse.UserId, tblStatusUserCourse.theme_id)=2)
				-- get Courses with result &gt; Threshold
				or (tblThemes.StatusThreshold is not null
				and tblThemes.StatusThreshold &lt; tblStatusUserCourse.BestComplete)

				-- adding general information for themes with status = 2 (mainly MONOLITHEN) to be included in the output
				-- adding general information for modules with status = 2 to be included in the output
				insert into #Result
				select
				tblStatusUserItemHistory.user_id,
				tblStatusUserItemHistory.item_id
				from tblStatusUserItemHistory
				INNER JOIN tblItems ON tblItems.id = tblStatusUserItemHistory.item_id AND tblItems.itemType_id IN (1,1001)
				join v_Users on v_Users.intUserCn = tblStatusUserItemHistory.user_id
				-- get courses done by user with result certificate
				where tblItems.deleted IS NULL
				-- adding general information for themes with status = 2 (mainly MONOLITHEN) to be included in the output
				AND tblStatusUserItemHistory.status = 2
				AND tblStatusUserItemHistory.endDate IS NULL
				AND NOT EXISTS(
				SELECT TOP 1 * FROM #Result
				WHERE #Result.item_id = tblStatusUserItemHistory.item_id
				AND
				#Result.user_id = tblStatusUserItemHistory.user_id
				)

				-- add passed Tests
				insert into #Result
				select
				v_Users.intUserCn,
				tblItems.id
				from tblTasStatsTestSessions
				join v_Users on v_Users.intUserCn = tblTasStatsTestSessions.user_id
				join tblTasTests on tblTasTests.id = tblTasStatsTestSessions.test_id
				join tblItems on tblItems.id = tblTasTests.id
				where passed=1
				AND v_Users.userStatus &lt;&gt; 2
				and user_id is not null
				and DateDiff( DAY,tblTasStatsTestSessions.endDate,GETDATE()) &lt; 365
				group by v_Users.intUserCn, tblItems.id

				-- get Total Result
				select
				CAST(tblItems.tag AS NVARCHAR(1024)) as Account,
				CAST(v_Users.descUserCn AS NVARCHAR(64)) as Kennung,
				CASE WHEN 
					ISNULL(tblItems.overrideSpanMonths,0) &gt; 0
          OR certificationType = 2
					OR certificationType = 3
        THEN
					FORMAT([dbo].[fn_GetUserModuleItemLastPassedDate](user_id, item_id),'yyyy-MM-dd')
				ELSE
					NULL
				END AS lastRecertification
				from #Result
				INNER JOIN tblItems ON tblItems.id = #Result.item_id
				INNER JOIN v_Users ON v_Users.intUserCn = #Result.user_id
				where ISNULL(tblItems.tag,'') &lt;&gt; ''
				AND v_Users.userStatus &lt;&gt; 2
				-- drop temp table
				drop table #Result
			</command>
		</Report>
	</Reports>
</ReportsExport>