USE [msdb]
GO

/****** Object:  Job [Jobs 1 dia]    Script Date: 02/15/2017 00:13:32 ******/
BEGIN TRANSACTION
DECLARE @ReturnCode INT
SELECT @ReturnCode = 0
/****** Object:  JobCategory [[Uncategorized (Local)]]]    Script Date: 02/15/2017 00:13:32 ******/
IF NOT EXISTS (SELECT name FROM msdb.dbo.syscategories WHERE name=N'[Uncategorized (Local)]' AND category_class=1)
BEGIN
EXEC @ReturnCode = msdb.dbo.sp_add_category @class=N'JOB', @type=N'LOCAL', @name=N'[Uncategorized (Local)]'
IF (@@ERROR <> 0 OR @ReturnCode <> 0) GOTO QuitWithRollback

END

DECLARE @jobId BINARY(16)
EXEC @ReturnCode =  msdb.dbo.sp_add_job @job_name=N'Jobs 1 dia', 
		@enabled=1, 
		@notify_level_eventlog=0, 
		@notify_level_email=0, 
		@notify_level_netsend=0, 
		@notify_level_page=0, 
		@delete_level=0, 
		@description=N'No description available.', 
		@category_name=N'[Uncategorized (Local)]', 
		@owner_login_name=N'sa', @job_id = @jobId OUTPUT
IF (@@ERROR <> 0 OR @ReturnCode <> 0) GOTO QuitWithRollback
/****** Object:  Step [TOP diario]    Script Date: 02/15/2017 00:13:32 ******/
EXEC @ReturnCode = msdb.dbo.sp_add_jobstep @job_id=@jobId, @step_name=N'TOP diario', 
		@step_id=1, 
		@cmdexec_success_code=0, 
		@on_success_action=3, 
		@on_success_step_id=0, 
		@on_fail_action=2, 
		@on_fail_step_id=0, 
		@retry_attempts=0, 
		@retry_interval=0, 
		@os_run_priority=0, @subsystem=N'TSQL', 
		@command=N'DECLARE
@name 		varchar(10),
@acc 		varchar(10),
@dado 		int,
@tipo 		smallint,
@WC int,
@WP int,
@GP int,
@XP int,
@VIP1 int,
@VIP2 int,
@VIP3 int,
@EVENTOS int

SET @tipo = ''1'';			-- Nao mudar

-- PRIMEIRO COLOCADO
SELECT TOP 1 @acc = AccountID, @name = Name, @dado = reset_diario from  character
where (select appl_days from memb_info where memb___id= accountid) > GETDATE()-15 order by reset_diario desc,resetcount desc
 
IF @dado > 0 
BEGIN
SET @WC 	=0; 		-- premio em creditos
SET @WP 	=0;		-- premio em mgolds
SET @GP 	=500;		-- premio em golds
SET @XP 	=500;		-- premio em exp
SET @VIP1 	=2;		-- premio apenas para vip nivel 0 e 1
SET @VIP2 	=0;		-- premio apenas para vip nivel 2
SET @VIP3 	=0;		-- premio apenas para vip nivel 3
SET @EVENTOS 	=0;		-- premio em pontos de eventos geral

EXEC PREMIAR_TOPS @acc, @name, @WC, @WP, @GP, @XP, @VIP1, @VIP2, @VIP3, @EVENTOS
INSERT INTO top_diario ( nome, dado,tipo,rank ) VALUES (@name,@dado,@tipo,''1'')

update character set reset_diario=0 where name = @name and reset_diario > 0

END

-- SEGUNDO COLOCADO
SELECT TOP 1 @acc = AccountID, @name = Name, @dado = reset_diario from  character
where (select appl_days from memb_info where memb___id= accountid) > GETDATE()-15 order by reset_diario desc,resetcount desc
 
IF @dado > 0 
BEGIN
SET @WC 	=0; 		-- premio em creditos
SET @WP 	=0;		-- premio em mgolds
SET @GP 	=400;		-- premio em golds
SET @XP 	=400;		-- premio em exp
SET @VIP1 	=2;		-- premio apenas para vip nivel 0 e 1
SET @VIP2 	=0;		-- premio apenas para vip nivel 2
SET @VIP3 	=0;		-- premio apenas para vip nivel 3
SET @EVENTOS 	=0;		-- premio em pontos de eventos geral

EXEC PREMIAR_TOPS @acc, @name, @WC, @WP, @GP, @XP, @VIP1, @VIP2, @VIP3, @EVENTOS
INSERT INTO top_diario ( nome, dado,tipo,rank ) VALUES (@name,@dado,@tipo,''2'')

update character set reset_diario=0 where name = @name and reset_diario > 0

END

-- TERCEIRO COLOCADO
SELECT TOP 1 @acc = AccountID, @name = Name, @dado = reset_diario from  character
where (select appl_days from memb_info where memb___id= accountid) > GETDATE()-15 order by reset_diario desc,resetcount desc
 
IF @dado > 0 
BEGIN
SET @WC 	=0; 		-- premio em creditos
SET @WP 	=0;		-- premio em mgolds
SET @GP 	=300;		-- premio em golds
SET @XP 	=300;		-- premio em exp
SET @VIP1 	=2;		-- premio apenas para vip nivel 0 e 1
SET @VIP2 	=0;		-- premio apenas para vip nivel 2
SET @VIP3 	=0;		-- premio apenas para vip nivel 3
SET @EVENTOS 	=0;		-- premio em pontos de eventos geral

EXEC PREMIAR_TOPS @acc, @name, @WC, @WP, @GP, @XP, @VIP1, @VIP2, @VIP3, @EVENTOS
INSERT INTO top_diario ( nome, dado,tipo,rank ) VALUES (@name,@dado,@tipo,''3'')

update character set reset_diario=0 where name = @name and reset_diario > 0

END

SET @tipo = ''2'';			-- Nao mudar

-- PRIMEIRO COLOCADO
SELECT TOP 1 @acc = AccountID, @name = Name, @dado = reset_diario from  character order by reset_diario desc,resetcount desc
 
IF @dado > 0 
BEGIN
SET @WC 	=0; 		-- premio em creditos
SET @WP 	=0;		-- premio em mgolds
SET @GP 	=300;		-- premio em golds
SET @XP 	=300;		-- premio em exp
SET @VIP1 	=2;		-- premio apenas para vip nivel 0 e 1
SET @VIP2 	=0;		-- premio apenas para vip nivel 2
SET @VIP3 	=0;		-- premio apenas para vip nivel 3
SET @EVENTOS 	=0;		-- premio em pontos de eventos geral

EXEC PREMIAR_TOPS @acc, @name, @WC, @WP, @GP, @XP, @VIP1, @VIP2, @VIP3, @EVENTOS
INSERT INTO top_diario ( nome, dado,tipo,rank ) VALUES (@name,@dado,@tipo,''1'')

update character set reset_diario=0 where name = @name and reset_diario > 0

END

-- SEGUNDO COLOCADO
SELECT TOP 1 @acc = AccountID, @name = Name, @dado = reset_diario from  character order by reset_diario desc,resetcount desc
 
IF @dado > 0 
BEGIN
SET @WC 	=0; 		-- premio em creditos
SET @WP 	=0;		-- premio em mgolds
SET @GP 	=200;		-- premio em golds
SET @XP 	=200;		-- premio em exp
SET @VIP1 	=2;		-- premio apenas para vip nivel 0 e 1
SET @VIP2 	=0;		-- premio apenas para vip nivel 2
SET @VIP3 	=0;		-- premio apenas para vip nivel 3
SET @EVENTOS 	=0;		-- premio em pontos de eventos geral

EXEC PREMIAR_TOPS @acc, @name, @WC, @WP, @GP, @XP, @VIP1, @VIP2, @VIP3, @EVENTOS
INSERT INTO top_diario ( nome, dado,tipo,rank ) VALUES (@name,@dado,@tipo,''2'')

update character set reset_diario=0 where name = @name and reset_diario > 0

END

-- TERCEIRO COLOCADO
SELECT TOP 1 @acc = AccountID, @name = Name, @dado = reset_diario from  character order by reset_diario desc,resetcount desc
 
IF @dado > 0 
BEGIN
SET @WC 	=0; 		-- premio em creditos
SET @WP 	=0;		-- premio em mgolds
SET @GP 	=100;		-- premio em golds
SET @XP 	=100;		-- premio em exp
SET @VIP1 	=2;		-- premio apenas para vip nivel 0 e 1
SET @VIP2 	=0;		-- premio apenas para vip nivel 2
SET @VIP3 	=0;		-- premio apenas para vip nivel 3
SET @EVENTOS 	=0;		-- premio em pontos de eventos geral

EXEC PREMIAR_TOPS @acc, @name, @WC, @WP, @GP, @XP, @VIP1, @VIP2, @VIP3, @EVENTOS
INSERT INTO top_diario ( nome, dado,tipo,rank ) VALUES (@name,@dado,@tipo,''3'')

END

update character set reset_diario = 0 where reset_diario > 0

SET @tipo = ''3'';			-- Nao mudar

-- PRIMEIRO COLOCADO
SELECT TOP 1 @acc = AccountID, @name = Name, @dado = mresets_diario from  character order by mresets_diario desc,masterresetcount desc
 
IF @dado > 0 
BEGIN
SET @WC 	=0; 		-- premio em creditos
SET @WP 	=0;		-- premio em mgolds
SET @GP 	=300;		-- premio em golds
SET @XP 	=300;		-- premio em exp
SET @VIP1 	=2;		-- premio apenas para vip nivel 0 e 1
SET @VIP2 	=0;		-- premio apenas para vip nivel 2
SET @VIP3 	=0;		-- premio apenas para vip nivel 3
SET @EVENTOS 	=0;		-- premio em pontos de eventos geral

EXEC PREMIAR_TOPS @acc, @name, @WC, @WP, @GP, @XP, @VIP1, @VIP2, @VIP3, @EVENTOS
INSERT INTO top_diario ( nome, dado,tipo,rank ) VALUES (@name,@dado,@tipo,''1'')

update character set mresets_diario=0 where name = @name and mresets_diario > 0

END

-- SEGUNDO COLOCADO
SELECT TOP 1 @acc = AccountID, @name = Name, @dado = mresets_diario from  character order by mresets_diario desc,masterresetcount desc
 
IF @dado > 0 
BEGIN
SET @WC 	=0; 		-- premio em creditos
SET @WP 	=0;		-- premio em mgolds
SET @GP 	=200;		-- premio em golds
SET @XP 	=200;		-- premio em exp
SET @VIP1 	=2;		-- premio apenas para vip nivel 0 e 1
SET @VIP2 	=0;		-- premio apenas para vip nivel 2
SET @VIP3 	=0;		-- premio apenas para vip nivel 3
SET @EVENTOS 	=0;		-- premio em pontos de eventos geral

EXEC PREMIAR_TOPS @acc, @name, @WC, @WP, @GP, @XP, @VIP1, @VIP2, @VIP3, @EVENTOS
INSERT INTO top_diario ( nome, dado,tipo,rank ) VALUES (@name,@dado,@tipo,''2'')

update character set mresets_diario=0 where name = @name and mresets_diario > 0

END

-- TERCEIRO COLOCADO
SELECT TOP 1 @acc = AccountID, @name = Name, @dado = mresets_diario from  character order by mresets_diario desc,masterresetcount desc
 
IF @dado > 0 
BEGIN
SET @WC 	=0; 		-- premio em creditos
SET @WP 	=0;		-- premio em mgolds
SET @GP 	=100;		-- premio em golds
SET @XP 	=100;		-- premio em exp
SET @VIP1 	=2;		-- premio apenas para vip nivel 0 e 1
SET @VIP2 	=0;		-- premio apenas para vip nivel 2
SET @VIP3 	=0;		-- premio apenas para vip nivel 3
SET @EVENTOS 	=0;		-- premio em pontos de eventos geral

EXEC PREMIAR_TOPS @acc, @name, @WC, @WP, @GP, @XP, @VIP1, @VIP2, @VIP3, @EVENTOS
INSERT INTO top_diario ( nome, dado,tipo,rank ) VALUES (@name,@dado,@tipo,''3'')

END

update character set mresets_diario = 0 where mresets_diario > 0
', 
		@database_name=N'MuOnline', 
		@flags=0
IF (@@ERROR <> 0 OR @ReturnCode <> 0) GOTO QuitWithRollback
/****** Object:  Step [Banidos]    Script Date: 02/15/2017 00:13:32 ******/
EXEC @ReturnCode = msdb.dbo.sp_add_jobstep @job_id=@jobId, @step_name=N'Banidos', 
		@step_id=2, 
		@cmdexec_success_code=0, 
		@on_success_action=3, 
		@on_success_step_id=0, 
		@on_fail_action=2, 
		@on_fail_step_id=0, 
		@retry_attempts=0, 
		@retry_interval=0, 
		@os_run_priority=0, @subsystem=N'TSQL', 
		@command=N'update character set dia_bloc = dia_bloc - 1 where ctlcode=1 and dia_bloc <> ''9999'' and dia_bloc >0

update character set ctlcode=0 where ctlcode = 1 and dia_bloc= 0', 
		@database_name=N'MuOnline', 
		@flags=0
IF (@@ERROR <> 0 OR @ReturnCode <> 0) GOTO QuitWithRollback
/****** Object:  Step [Gm premios]    Script Date: 02/15/2017 00:13:32 ******/
EXEC @ReturnCode = msdb.dbo.sp_add_jobstep @job_id=@jobId, @step_name=N'Gm premios', 
		@step_id=3, 
		@cmdexec_success_code=0, 
		@on_success_action=3, 
		@on_success_step_id=0, 
		@on_fail_action=2, 
		@on_fail_step_id=0, 
		@retry_attempts=0, 
		@retry_interval=0, 
		@os_run_priority=0, @subsystem=N'TSQL', 
		@command=N'
DECLARE @Acc varchar(10),@acc_gm varchar(10),@eventos_dia int,@exp_gm int,@total int
DECLARE LISTA CURSOR LOCAL FOR 
select acc_player,acc_gm from mk_character_gm
OPEN LISTA 
FETCH NEXT FROM LISTA INTO @Acc,@acc_gm
WHILE @@FETCH_STATUS = 0 
begin 

if (select nivel_gm from character where accountid=@acc_gm and nivel_gm>1)>2
	begin
		set @exp_gm = 400
	end
else
	begin 
		set @exp_gm = 300
	end


set @eventos_dia = (select evento_dia from character where accountid=@acc_gm and nivel_gm>1)

if @eventos_dia > 40
set @total = @exp_gm+@eventos_dia
else 
set @total = 0

UPDATE character set exp_war = exp_war+@total where accountid=@acc and nivel_gm=1

FETCH NEXT FROM LISTA INTO @Acc,@acc_gm
end 
CLOSE LISTA 
DEALLOCATE LISTA 


Update character set evento_dia=0 where evento_dia > 0', 
		@database_name=N'MuOnline', 
		@flags=0
IF (@@ERROR <> 0 OR @ReturnCode <> 0) GOTO QuitWithRollback
/****** Object:  Step [medalhas]    Script Date: 02/15/2017 00:13:33 ******/
EXEC @ReturnCode = msdb.dbo.sp_add_jobstep @job_id=@jobId, @step_name=N'medalhas', 
		@step_id=4, 
		@cmdexec_success_code=0, 
		@on_success_action=3, 
		@on_success_step_id=0, 
		@on_fail_action=2, 
		@on_fail_step_id=0, 
		@retry_attempts=0, 
		@retry_interval=0, 
		@os_run_priority=0, @subsystem=N'TSQL', 
		@command=N'DECLARE 
@Acc varchar(10),
@nome varchar(10)

set @nome = (select top 1 name from RankingDevilSquare order by Score desc)
set @Acc = (select top 1 AccountID from character where Name = @nome)

if exists (select name from MK_MEDALHAS where Name = @nome)
	update MK_MEDALHAS set medal_ds = 1 where Name = @nome and medal_ds=0
else
BEGIN
	IF @nome is not null and @acc is not null
	INSERT INTO MK_MEDALHAS (login,Name,medal_ds) VALUES (@Acc, @nome, 1)
END

set @nome = (select top 1 name from RankingBloodCastle order by Score desc)
set @Acc = (select top 1 AccountID from character where Name = @nome)

if exists (select name from MK_MEDALHAS where Name = @nome)
	update MK_MEDALHAS set medal_bc = 1 where Name = @nome and medal_bc=0
else
BEGIN
	IF @nome is not null and @acc is not null
	INSERT INTO MK_MEDALHAS (login,Name,medal_bc) VALUES (@Acc, @nome, 1)
END

DECLARE LISTA CURSOR LOCAL FOR 
select memb___id from memb_info where missoes > 34
OPEN LISTA 
FETCH NEXT FROM LISTA INTO @Acc
WHILE @@FETCH_STATUS = 0 
begin 

if exists (select login from MK_MEDALHAS where login = @Acc)
	begin
		update MK_MEDALHAS set medal_missao = 1 where login = @Acc and medal_missao=0
	end
else
	begin 
		set @nome = (select top 1 name from Character where accountid = @Acc order by exp_war desc, MasterResetCount desc, ResetCount desc, cLevel desc)
		IF @nome is not null and @acc is not null
		INSERT INTO MK_MEDALHAS (login,Name,medal_missao) VALUES (@Acc, @nome, 1)
	end
FETCH NEXT FROM LISTA INTO @Acc
end 
CLOSE LISTA 
DEALLOCATE LISTA 

DECLARE LISTA CURSOR LOCAL FOR 
SELECT login_r FROM mk_reputacao GROUP BY login_r HAVING (COUNT(*) > 49)
OPEN LISTA 
FETCH NEXT FROM LISTA INTO @Acc
WHILE @@FETCH_STATUS = 0 
begin 
if exists (select login from MK_MEDALHAS where login = @Acc)
	begin
		update MK_MEDALHAS set medal_reputacao = 1 where login = @Acc and medal_reputacao=0
	end
else
	begin 
		set @nome = (select top 1 name from Character where accountid = @Acc order by exp_war desc, MasterResetCount desc, ResetCount desc, cLevel desc)
		IF @nome is not null and @acc is not null
		INSERT INTO MK_MEDALHAS (login,Name,medal_reputacao) VALUES (@Acc, @nome, 1)
	end
FETCH NEXT FROM LISTA INTO @Acc
end 
CLOSE LISTA 
DEALLOCATE LISTA

DECLARE LISTA CURSOR LOCAL FOR 
SELECT accountid,name FROM character where resetcount>999
OPEN LISTA 
FETCH NEXT FROM LISTA INTO @Acc, @nome 
WHILE @@FETCH_STATUS = 0 
begin 
if exists (select name from MK_MEDALHAS where name = @nome)
	begin
		update MK_MEDALHAS set medal_resets = 1 where name = @nome and medal_resets=0
	end
else
	begin 
		IF @nome is not null and @acc is not null
		INSERT INTO MK_MEDALHAS (login,Name,medal_resets) VALUES (@Acc, @nome, 1)
	end
FETCH NEXT FROM LISTA INTO @Acc, @nome 
end 
CLOSE LISTA 
DEALLOCATE LISTA

DECLARE LISTA CURSOR LOCAL FOR 
SELECT accountid,name FROM character where masterresetcount>499
OPEN LISTA 
FETCH NEXT FROM LISTA INTO @Acc, @nome 
WHILE @@FETCH_STATUS = 0 
begin 
if exists (select name from MK_MEDALHAS where name = @nome)
	begin
		update MK_MEDALHAS set medal_mresets = 1 where name = @nome and medal_mresets=0
	end
else
	begin 
		IF @nome is not null and @acc is not null
		INSERT INTO MK_MEDALHAS (login,Name,medal_mresets) VALUES (@Acc, @nome, 1)
	end
FETCH NEXT FROM LISTA INTO @Acc, @nome 
end 
CLOSE LISTA 
DEALLOCATE LISTA

DECLARE LISTA CURSOR LOCAL FOR 
SELECT accountid,name FROM character where exp_war>149999
OPEN LISTA 
FETCH NEXT FROM LISTA INTO @Acc, @nome 
WHILE @@FETCH_STATUS = 0 
begin 
if exists (select name from MK_MEDALHAS where name = @nome)
	begin
		update MK_MEDALHAS set medal_exp = 1 where name = @nome and medal_exp=0
	end
else
	begin 
		IF @nome is not null and @acc is not null
		INSERT INTO MK_MEDALHAS (login,Name,medal_exp) VALUES (@Acc, @nome, 1)
	end
FETCH NEXT FROM LISTA INTO @Acc, @nome 
end 
CLOSE LISTA 
DEALLOCATE LISTA

DECLARE LISTA CURSOR LOCAL FOR 
SELECT name FROM Log_custom_arena group by name HAVING SUM(valor) > 49999
OPEN LISTA 
FETCH NEXT FROM LISTA INTO @nome 
WHILE @@FETCH_STATUS = 0 
begin 
  if exists (select name from MK_MEDALHAS where name = @nome)
	begin
		update MK_MEDALHAS set medal_rei_conquistas = 1 where name = @nome and medal_rei_conquistas=0
	end
else
	begin 
        		set @acc = (select top 1 AccountID from Character where Name=@nome)
		IF @nome is not null and @acc is not null
		INSERT INTO MK_MEDALHAS (login,Name,medal_rei_conquistas) VALUES (@Acc, @nome, 1)
	end
FETCH NEXT FROM LISTA INTO @nome 
end 
CLOSE LISTA 
DEALLOCATE LISTA

DECLARE LISTA CURSOR LOCAL FOR 
SELECT memb___id from MEMB_INFO where AccountExpireDate > GETDATE() + 150
OPEN LISTA 
FETCH NEXT FROM LISTA INTO @Acc
WHILE @@FETCH_STATUS = 0 
begin 
if exists (select login from MK_MEDALHAS where login = @Acc)
	begin
		update MK_MEDALHAS set medal_vip = 1 where login = @Acc and medal_vip=0
	end
else
	begin 
		set @nome = (select top 1 name from Character where accountid = @Acc order by exp_war desc, MasterResetCount desc, ResetCount desc, cLevel desc)
		IF @nome is not null and @acc is not null
		INSERT INTO MK_MEDALHAS (login,Name,medal_vip) VALUES (@Acc, @nome, 1)
	end
FETCH NEXT FROM LISTA INTO @Acc
end 
CLOSE LISTA 
DEALLOCATE LISTA

DECLARE LISTA CURSOR LOCAL FOR 
SELECT name FROM rankingduel group by name HAVING SUM(winscore) > 99
OPEN LISTA 
FETCH NEXT FROM LISTA INTO @nome 
WHILE @@FETCH_STATUS = 0 
begin 
  if exists (select name from MK_MEDALHAS where name = @nome)
	begin
		update MK_MEDALHAS set medal_duel = 1 where name = @nome and medal_duel=0
	end
else
	begin 
       		set @acc = (select top 1 AccountID from Character where Name=@nome)
		IF @nome is not null and @acc is not null
		INSERT INTO MK_MEDALHAS (login,Name,medal_duel) VALUES (@Acc, @nome, 1)
	end
FETCH NEXT FROM LISTA INTO @nome 
end 
CLOSE LISTA 
DEALLOCATE LISTA', 
		@database_name=N'MuOnline', 
		@flags=0
IF (@@ERROR <> 0 OR @ReturnCode <> 0) GOTO QuitWithRollback
/****** Object:  Step [mdar_mail]    Script Date: 02/15/2017 00:13:33 ******/
EXEC @ReturnCode = msdb.dbo.sp_add_jobstep @job_id=@jobId, @step_name=N'mdar_mail', 
		@step_id=5, 
		@cmdexec_success_code=0, 
		@on_success_action=3, 
		@on_success_step_id=0, 
		@on_fail_action=2, 
		@on_fail_step_id=0, 
		@retry_attempts=0, 
		@retry_interval=0, 
		@os_run_priority=0, @subsystem=N'TSQL', 
		@command=N'update mk_mudar_mail set dias=dias-1 where dias > 0

update memb_info set mail_addr = (select novo from mk_mudar_mail where login=memb_info.memb___id COLLATE database_default)
FROM memb_info join mk_mudar_mail on memb_info.memb___id = mk_mudar_mail.login COLLATE database_default
where mk_mudar_mail.dias=0

delete from mk_mudar_mail where dias = 0
', 
		@database_name=N'MuOnline', 
		@flags=0
IF (@@ERROR <> 0 OR @ReturnCode <> 0) GOTO QuitWithRollback
/****** Object:  Step [NULL]    Script Date: 02/15/2017 00:13:33 ******/
EXEC @ReturnCode = msdb.dbo.sp_add_jobstep @job_id=@jobId, @step_name=N'NULL', 
		@step_id=6, 
		@cmdexec_success_code=0, 
		@on_success_action=3, 
		@on_success_step_id=0, 
		@on_fail_action=2, 
		@on_fail_step_id=0, 
		@retry_attempts=0, 
		@retry_interval=0, 
		@os_run_priority=0, @subsystem=N'TSQL', 
		@command=N'delete from mk_murkut_news where id_news < (select max(id_news)from MK_Murkut_News)-3000

update memb_info set msg_num=1 where msg_num>8 and msg_viu=1
update memb_info set msg_viu=0 where msg_viu=1

DELETE Optiondata where (SELECT COUNT(*) FROM character where name = optiondata.Name )=0
DELETE mk_quest where (SELECT COUNT(*) FROM character where name = mk_quest.Name )=0
DELETE mk_pagamentos where (SELECT COUNT(*) FROM memb_info where memb___id = mk_pagamentos.login collate database_default)=0

delete from mk_chat where id_chat < (select max(id_chat)from mk_chat)-1000

delete from mk_chat_staff where id_chat < (select max(id_chat)from mk_chat_staff)-100

update guild set g_count = (select count(*) from guildmember where g_name=guild.g_name)

--update server set ranking_dv=1', 
		@database_name=N'MuOnline', 
		@flags=0
IF (@@ERROR <> 0 OR @ReturnCode <> 0) GOTO QuitWithRollback
/****** Object:  Step [REMOVER EXP, RESET, MRESETS]    Script Date: 02/15/2017 00:13:33 ******/
EXEC @ReturnCode = msdb.dbo.sp_add_jobstep @job_id=@jobId, @step_name=N'REMOVER EXP, RESET, MRESETS', 
		@step_id=7, 
		@cmdexec_success_code=0, 
		@on_success_action=1, 
		@on_success_step_id=0, 
		@on_fail_action=2, 
		@on_fail_step_id=0, 
		@retry_attempts=0, 
		@retry_interval=0, 
		@os_run_priority=0, @subsystem=N'TSQL', 
		@command=N'UPDATE Character set exp_war = exp_war - 1000 where exp_war >= 300000 and nivel_gm<2
UPDATE Character set exp_war = exp_war - 500 where exp_war >= 150000 and exp_war < 300000 and nivel_gm<2
UPDATE Character set exp_war = exp_war - 300 where exp_war >= 50000 and exp_war < 150000 and nivel_gm<2

UPDATE Character set ResetCount = ResetCount - 100 where ResetCount >= 1000 and nivel_gm<2
UPDATE Character set ResetCount = ResetCount - 50 where ResetCount >= 500 and ResetCount < 1000 and nivel_gm<2
UPDATE Character set ResetCount = ResetCount - 10 where ResetCount >= 300 and ResetCount < 500 and nivel_gm<2
UPDATE Character set ResetCount = ResetCount - 1 where ResetCount >= 100 and ResetCount < 300 and nivel_gm<2

UPDATE Character set MasterResetCount = MasterResetCount - 50 where MasterResetCount >= 1000 and nivel_gm<2
UPDATE Character set MasterResetCount = MasterResetCount - 30 where MasterResetCount >= 500 and MasterResetCount < 1000 and nivel_gm<2
UPDATE Character set MasterResetCount = MasterResetCount - 5 where MasterResetCount >= 100 and MasterResetCount < 500 and nivel_gm<2
UPDATE Character set MasterResetCount = MasterResetCount - 1 where MasterResetCount >= 1 and MasterResetCount < 100 and nivel_gm<2
', 
		@database_name=N'MuOnline', 
		@flags=0
IF (@@ERROR <> 0 OR @ReturnCode <> 0) GOTO QuitWithRollback
EXEC @ReturnCode = msdb.dbo.sp_update_job @job_id = @jobId, @start_step_id = 1
IF (@@ERROR <> 0 OR @ReturnCode <> 0) GOTO QuitWithRollback
EXEC @ReturnCode = msdb.dbo.sp_add_jobschedule @job_id=@jobId, @name=N'tesmp', 
		@enabled=1, 
		@freq_type=4, 
		@freq_interval=1, 
		@freq_subday_type=1, 
		@freq_subday_interval=0, 
		@freq_relative_interval=0, 
		@freq_recurrence_factor=0, 
		@active_start_date=20160730, 
		@active_end_date=99991231, 
		@active_start_time=0, 
		@active_end_time=235959, 
		@schedule_uid=N'ea133359-3151-4ae6-97af-679d0e65e3d8'
IF (@@ERROR <> 0 OR @ReturnCode <> 0) GOTO QuitWithRollback
EXEC @ReturnCode = msdb.dbo.sp_add_jobserver @job_id = @jobId, @server_name = N'(local)'
IF (@@ERROR <> 0 OR @ReturnCode <> 0) GOTO QuitWithRollback
COMMIT TRANSACTION
GOTO EndSave
QuitWithRollback:
    IF (@@TRANCOUNT > 0) ROLLBACK TRANSACTION
EndSave:

GO


