﻿<?xml version="1.0" encoding="utf-8"?>
<ReportsExport>
  <Reports>
    <Report id="109afc0e-159e-4324-a199-1b401a5b6f78" codekey="ERGO_e-Campus_PTD_Gesamtdatenbankabzug" categoryCodekey="CreditPoints" name="PTD_Gesamtdatenbankabzug" description="Gibt die erworbenen Bildungszeiten Benutzer und Bausteine zurück die der Qualifizierung &quot;PTD Gesamtdatenbankabzug&quot; zugeordnet sind.">
      <MetaData created="2021-10-07T12:27:17" createdBy="Administrator, Albrecht (Administrator)" createdBy_user_id="1" modified="2023-10-19T11:41:05" modifiedBy="Kaiser, Jan-Patrick (245527)" modifiedBy_user_id="101393" />
      <ExecutionDetails format="TableResult" commandType="SqlCommandOrQuery" exportHandler="" adminControl="" exportMultipleTablesToSheets="False" datesWithTime="False" extraParams="" />
      <Mandators mandatorMode="OnlyOwner" mandator_id="bfa70f6b-484c-49da-9ad7-1ccd8f0d684c" mandatorName="ERGO_e-Campus" isStandard="False" isUsedByMenu="False" />
      <Parameters>
        <Parameter id="bf72399d-7582-4b2a-a06c-8d47afe576f2" isRequired="False" allowMultiSelect="False" name="Von" contextName="Von" defaultValue="" renderHint="Undefined" disableParameter="DontDisable" />
        <Parameter id="80245dc5-ca96-4c76-9449-2b5d07b129e9" isRequired="False" allowMultiSelect="False" name="Bis" contextName="Bis" defaultValue="" renderHint="Undefined" disableParameter="DontDisable" />
      </Parameters>
      <Roles>
        <Role id="90" />
      </Roles>
      <command>/**
 * Report Name: ERGO_e-Campus_PTD_Gesamtdatenabzug
**/

--DECLARE @mandator_id UNIQUEIDENTIFIER = (SELECT id FROM tblMandators WHERE name = 'ERGO_e-Campus')

--DECLARE @StartDate DATETIME
--DECLARE @EndDate DATETIME

DECLARE @module_id UNIQUEIDENTIFIER = (SELECT id FROM tblItems WHERE title = 'Gesamtdatenbankabzug alle Lernprogramme' and itemType_id = 1001)

IF (@EndDate IS NULL)
BEGIN
	SET @EndDate = GETDATE()
END

CREATE TABLE #users(
	UserCn INT
)

SELECT suih.* 
INTO #usersAndStates
FROM tblModuleItems mi
INNER JOIN tblStatusUserItemHistory suih ON suih.item_id = mi.item_id 
	and suih.status = 2 
	AND (@StartDate IS NULL OR CONVERT(date,suih.startDate) &gt;= @StartDate)
	AND (@EndDate IS NULL OR CONVERT(date,suih.startDate) &lt;= @EndDate)
	AND (CONVERT(date,suih.endDate) IS NULL OR CONVERT(date,suih.endDate) &lt;= @EndDate)
        WHERE mi.module_id = @module_id

        SELECT
        (SELECT descUserCn FROM tableUsers WHERE intUserCn = u.user_id) AS PNR,
        (SELECT title FROM tblItems WHERE id = u.item_id) AS [Bausteintitel],
        (SELECT titleForLearners FROM tblItems WHERE id = u.item_id) AS [Bausteintitel für Lerner],
        (SELECT TOP 1 mainVersion FROM tblVersionMap WHERE id = u.item_id ORDER BY mainVersion DESC) AS [letzte Version],
        u.item_version AS [Versionsnummer],
        CASE
        WHEN (SELECT itemType_id FROM tblItems WHERE id = u.item_id) = 1 THEN
        (SELECT CAST(learningDuration AS DECIMAL(10,1)) FROM tblThemeVersions WHERE id = u.item_id AND version = (
        SELECT TOP 1 subVersion FROM tblVersionMap WHERE id = u.item_id and tableName = 'tblThemeVersions'
        AND mainVersion = (SELECT TOP 1 mainVersion FROM tblVersionMap WHERE id = u.item_id ORDER BY mainVersion DESC)
        ))
        ELSE
        (SELECT CAST(timeLimit AS DECIMAL(10,1)) FROM tblTasTestVersions WHERE id = u.item_id AND version = (
        SELECT TOP 1 subVersion FROM tblVersionMap WHERE id = u.item_id and tableName = 'tblThemeVersions'
        AND mainVersion = (SELECT TOP 1 mainVersion FROM tblVersionMap WHERE id = u.item_id ORDER BY mainVersion DESC)
        ))
        END AS [Lerndauer in Minuten],
        (SELECT CAST( (SUM(durationSeconds) / 60.0) AS DECIMAL(10,1))
        FROM tblStatsThemeSessions tsts2
        WHERE tsts2.theme_id = u.item_id
        AND tsts2.user_id = u.user_id) AS [Bearbeitungszeit in Min],
        (
        SELECT TOP 1 educationTime From tblUserItemScores uis WHERE uis.status_id = u.id
        ) AS [Bildungszeit in Min],
        ISNULL(u.endDate, u.startDate) AS [Datum]
        FROM #usersAndStates u
        ORDER BY PNR

        IF OBJECT_ID('tempdb..#users') IS NOT NULL
        DROP TABLE #users

        IF OBJECT_ID('tempdb..#usersAndScores') IS NOT NULL
        DROP TABLE #usersAndScores

        IF OBJECT_ID('tempdb..#usersAndStates') IS NOT NULL
        DROP TABLE #usersAndStates
      </command>
    </Report>
  </Reports>
  <Parameters>
    <Parameter id="bf72399d-7582-4b2a-a06c-8d47afe576f2" isSystem="True" name="Von" reportParameterType_id="74253ba7-a386-4620-bff7-b65c16fe1e64" queryParameterName="@StartDate" />
    <Parameter id="80245dc5-ca96-4c76-9449-2b5d07b129e9" isSystem="True" name="Bis" reportParameterType_id="74253ba7-a386-4620-bff7-b65c16fe1e64" queryParameterName="@EndDate" />
  </Parameters>
  <ParameterTypes>
    <ParameterType id="74253ba7-a386-4620-bff7-b65c16fe1e64" isSystem="True" name="Date" datatype="Date" dataValueField="" dataTextField="" />
  </ParameterTypes>
</ReportsExport>