
/*ALIAS>prop_db*/
/*Hist_TBL>SQL_UPDATES_INCOMES*/

/*SQLStart>7040*/
	create or alter procedure CLEARBADTAKING
	as
	declare variable TAKING_ID integer;
	begin
	  FOR
		select t.t_id
		from taking t
		inner join taxorders tox on tox.to_id = t.t_appid1
		where t.t_appcode ='D' and tox.to_appchar='D'
		   and t.t_appid1 <> tox.to_docid
		   and not(tox.to_extnumber containing 'нп-')
		   and not(t.t_reasonnum containing 'нп-')
		into :taking_id
	  DO
	  Begin
		update taking set t_appcode = 'K' where t_id = :taking_id;
	  end

	  suspend;
	end;
/*SQLStop*/

/*SQLStart>7041*/
	execute procedure CLEARBADTAKING;
/*SQLStop*/

/*SQLStart>7042*/
	drop procedure CLEARBADTAKING;
/*SQLStop*/