﻿<?xml version="1.0" encoding="utf-8"?>
<ReportsExport>
  <Reports>
    <Report id="98df6a44-edb5-4991-99cb-9a6c673cdbfb" codekey="BISS_UnlockAllQuestionsInTasSeminar" categoryCodekey="TestsAndQuestions" name="Unlock all questions in TAS seminar" description="Unlock all questions in a selection tas seminar category (Lehrgang), from BISS/UnlockAllQuestionsInTasSeminar.sql">
      <MetaData created="2012-01-13T12:00:24" createdBy="Anton Administrator (Administrator)" createdBy_user_id="12" />
      <ExecutionDetails format="NoResult" commandType="SqlCommandOrQuery" exportHandler="" adminControl="" exportMultipleTablesToSheets="False" datesWithTime="False" extraParams="" />
      <Mandators mandatorMode="OnlyOwner" mandator_id="345bbab2-62a8-424d-a6e6-133aeab480a4" mandatorName="BISS" isStandard="False" isUsedByMenu="False" />
      <Roles />
      <command>-- Unlock all questions in a selection tas seminar category (Lehrgang)

-- Use this for testing:
-- declare @current_mandator_id uniqueidentifier
-- select @current_mandator_id=id from tblMandators where name='viwis'

-- define cursor
declare @otxt varchar(1000)
set @otxt = 'locked="True"'

declare curs cursor local fast_forward
for
select 
	id,
	textptr(questionXML),
	charindex(@otxt, questionXML)-1
from 
	tblTasQuestions 
where 
	mandator_id=@current_mandator_id and deleted is null and locked=1 and dbo.fn_GetCategoryIdForQuestion(tblTasQuestions.id, 1, 0)=@questionCategorySeminar_id

-- make loop
declare @ntxt varchar(1000)
set @ntxt = 'locked="False"'

declare @txtlen int
set @txtlen = len(@otxt)

declare @ptr binary(16)
declare @pos int
declare @id uniqueidentifier

-- Finally we can do our search and replace:

open curs

fetch next from curs into @id, @ptr, @pos

while @@fetch_status = 0
begin	
	updatetext tblTasQuestions.questionXML @ptr @pos @txtlen @ntxt
	update tblTasQuestions set locked = 0 where id=@id

	fetch next from curs into @id, @ptr, @pos	
end

close curs
deallocate curs
</command>
    </Report>
  </Reports>
</ReportsExport>