﻿<?xml version="1.0" encoding="utf-8"?>
<ReportsExport>
  <Reports>
    <Report id="53b32890-869c-4808-8fec-8bc7b5985b64" codekey="BissDeleteUsers" categoryCodekey="SpecialPurpose" name="Delet User" description="Es werden alle Benutzer, die 14 Tage oder länger in der Zielgruppe „Loeschen“ sind, aus der Plattform gelöscht">
      <MetaData created="2010-09-03T11:26:00" createdBy="Jochen Buckl" createdBy_user_id="12" modified="2016-07-04T12:42:58" modifiedBy="Rolle Administrator" />
      <ExecutionDetails format="NoResult" commandType="SqlCommandOrQuery" exportHandler="" adminControl="" exportMultipleTablesToSheets="False" datesWithTime="False" extraParams="" />
      <Mandators mandatorMode="OnlyOwner" mandator_id="cf85efc9-150b-4eee-8c20-929a112b658c" mandatorName="BISS" isStandard="False" isUsedByMenu="False" />
      <Roles>
        <Role id="90" />
      </Roles>
      <command>declare @mandator_id uniqueidentifier
        select @mandator_id=id from tblMandators where name='BISS'

        declare @targetGroup_id int
        select @targetGroup_id=id from tblTargetGroups where mandator_id=@mandator_id and title='Loeschen'

        declare @beforeDate datetime
        set @beforeDate = dateadd(day, -14, getdate())

        select distinct intUserCn as user_id
        into #tempUserIds 
        from v_Users
        where mandator_id=@mandator_id and blocked=1
        and (select top 1 addedTime from tblStatsUsersTargetGroups where tblStatsUsersTargetGroups.user_id=v_Users.intUserCn and tblStatsUsersTargetGroups.targetGroup_id=@targetGroup_id order by addedTime desc)&lt;@beforeDate

        declare @cursorUsers cursor
        set @cursorUsers = cursor static forward_only for
        select user_id from #tempUserIds

        declare @user_id int

        open @cursorUsers
        fetch next from @cursorUsers into @user_id
        while (@@fetch_status=0)
        begin
        -- print @user_id
        exec sp_DeleteUser @user_id=@user_id
        fetch next from @cursorUsers into @user_id
        end

        close @cursorUsers
        deallocate @cursorUsers

        drop table #tempUserIds
      </command>
    </Report>
  </Reports>
</ReportsExport>