create procedure sistema.sp_guardarRol
@numId int,
@txtRol varchar(300),
@numTipoRol int,
@dbResponse varchar(300) output,
@dbId int output
as
begin
	set nocount on;
	declare @dbCnt int;

	select @dbCnt = COUNT(*) from sistema.datos_roles where rol = @txtRol and estado = 1;
	if @dbCnt > 0
		begin
			select top(1) @numId = id from sistema.datos_roles where rol = @txtRol and estado = 1;
		end

	if @numId = 0
		begin
			insert into sistema.datos_roles(rol,idTipo) values(@txtRol,@numTipoRol);
			select @dbId = SCOPE_IDENTITY();
		end
	else
		begin
			set @dbId = @numId;
			update sistema.datos_roles set rol = @txtRol,idTipo = @numTipoRol where id = @dbId;
		end

	set @dbResponse = 'success';
end