Description
Properties
| Name | Value |
|---|---|
| ANSI Nulls ON | True |
| Quoted Identifier ON | True |
| Encrypted | False |
| Execute As | |
| Assembly |
Parameters
1| Name | Data Type | Length | Description |
|---|---|---|---|
| @todo | bit | 1 |
SQL Script
Copy
SET QUOTED_IDENTIFIER, ANSI_NULLS ON
GO
CREATE OR ALTER PROCEDURE dbo.asigna_cuit_juicios_automatico
@todo bit = 0 -- Mandar 1 si se quiere asignar a todos / 0 solo los created Ășltimas 24 hs
AS
BEGIN
SET NOCOUNT ON;
declare @id bigint
declare @cant_demandado bigint = 0
declare @cant_actor bigint = 0
declare @nombre varchar(500)
if (@todo = 0) -- solo los created Ășltimas 24 hs
begin
DECLARE C_demandado CURSOR FOR
select id_juicio, demandado
from juicios
where created >= getdate() - 1
and cuit_demandado is null and juicios.visible = 1 and len(ltrim(rtrim(demandado))) >= 5
and (select count(*) from padrones where padrones.nombre_persona = demandado and habilitado = 1 and identificador in ('CUIT','CUIL')) = 1
DECLARE C_actor CURSOR FOR
select id_juicio, actor
from juicios
where created >= getdate() - 1
and cuit_actor is null and juicios.visible = 1 and len(ltrim(rtrim(actor))) >= 5
and (select count(*) from padrones where padrones.nombre_persona = actor and habilitado = 1 and identificador in ('CUIT','CUIL')) = 1
end
else
begin
DECLARE C_demandado CURSOR FOR
select id_juicio, demandado
from juicios
where cuit_demandado is null and juicios.visible = 1 and len(ltrim(rtrim(demandado))) >= 5
and (select count(*) from padrones where padrones.nombre_persona = demandado and habilitado = 1 and identificador in ('CUIT','CUIL')) = 1
DECLARE C_actor CURSOR FOR
select id_juicio, actor
from juicios
where cuit_actor is null and juicios.visible = 1 and len(ltrim(rtrim(actor))) >= 5
and (select count(*) from padrones where padrones.nombre_persona = actor and habilitado = 1 and identificador in ('CUIT','CUIL')) = 1
end
-- select * from padrones where nombre_persona = 'srl'
OPEN C_demandado
FETCH NEXT FROM C_demandado INTO @id, @nombre
WHILE @@fetch_status = 0
BEGIN
set @cant_demandado = @cant_demandado + 1
update juicios
set fecha_asigna_cuit_demandado = getdate(),
usuario_asigna_cuit_demandado = 94437923,
cuit_demandado =
(select identificacion from padrones where padrones.nombre_persona = @nombre and habilitado = 1 and identificador in ('CUIT','CUIL'))
where id_juicio = @id
FETCH NEXT FROM C_demandado INTO @id, @nombre
END
CLOSE C_demandado
DEALLOCATE C_demandado
OPEN C_actor
FETCH NEXT FROM C_actor INTO @id, @nombre
WHILE @@fetch_status = 0
BEGIN
set @cant_actor = @cant_actor + 1
update juicios
set fecha_asigna_cuit_actor = getdate(),
usuario_asigna_cuit_actor = 94437923,
cuit_actor =
(select identificacion from padrones where padrones.nombre_persona = @nombre and habilitado = 1 and identificador in ('CUIT','CUIL'))
where id_juicio = @id
FETCH NEXT FROM C_actor INTO @id, @nombre
END
CLOSE C_actor
DEALLOCATE C_actor
select @cant_demandado as 'actualizados_demandado',
@cant_actor as 'actualizados_actor'
END
GO
GO
CREATE OR ALTER PROCEDURE dbo.asigna_cuit_juicios_automatico
@todo bit = 0 -- Mandar 1 si se quiere asignar a todos / 0 solo los created Ășltimas 24 hs
AS
BEGIN
SET NOCOUNT ON;
declare @id bigint
declare @cant_demandado bigint = 0
declare @cant_actor bigint = 0
declare @nombre varchar(500)
if (@todo = 0) -- solo los created Ășltimas 24 hs
begin
DECLARE C_demandado CURSOR FOR
select id_juicio, demandado
from juicios
where created >= getdate() - 1
and cuit_demandado is null and juicios.visible = 1 and len(ltrim(rtrim(demandado))) >= 5
and (select count(*) from padrones where padrones.nombre_persona = demandado and habilitado = 1 and identificador in ('CUIT','CUIL')) = 1
DECLARE C_actor CURSOR FOR
select id_juicio, actor
from juicios
where created >= getdate() - 1
and cuit_actor is null and juicios.visible = 1 and len(ltrim(rtrim(actor))) >= 5
and (select count(*) from padrones where padrones.nombre_persona = actor and habilitado = 1 and identificador in ('CUIT','CUIL')) = 1
end
else
begin
DECLARE C_demandado CURSOR FOR
select id_juicio, demandado
from juicios
where cuit_demandado is null and juicios.visible = 1 and len(ltrim(rtrim(demandado))) >= 5
and (select count(*) from padrones where padrones.nombre_persona = demandado and habilitado = 1 and identificador in ('CUIT','CUIL')) = 1
DECLARE C_actor CURSOR FOR
select id_juicio, actor
from juicios
where cuit_actor is null and juicios.visible = 1 and len(ltrim(rtrim(actor))) >= 5
and (select count(*) from padrones where padrones.nombre_persona = actor and habilitado = 1 and identificador in ('CUIT','CUIL')) = 1
end
-- select * from padrones where nombre_persona = 'srl'
OPEN C_demandado
FETCH NEXT FROM C_demandado INTO @id, @nombre
WHILE @@fetch_status = 0
BEGIN
set @cant_demandado = @cant_demandado + 1
update juicios
set fecha_asigna_cuit_demandado = getdate(),
usuario_asigna_cuit_demandado = 94437923,
cuit_demandado =
(select identificacion from padrones where padrones.nombre_persona = @nombre and habilitado = 1 and identificador in ('CUIT','CUIL'))
where id_juicio = @id
FETCH NEXT FROM C_demandado INTO @id, @nombre
END
CLOSE C_demandado
DEALLOCATE C_demandado
OPEN C_actor
FETCH NEXT FROM C_actor INTO @id, @nombre
WHILE @@fetch_status = 0
BEGIN
set @cant_actor = @cant_actor + 1
update juicios
set fecha_asigna_cuit_actor = getdate(),
usuario_asigna_cuit_actor = 94437923,
cuit_actor =
(select identificacion from padrones where padrones.nombre_persona = @nombre and habilitado = 1 and identificador in ('CUIT','CUIL'))
where id_juicio = @id
FETCH NEXT FROM C_actor INTO @id, @nombre
END
CLOSE C_actor
DEALLOCATE C_actor
select @cant_demandado as 'actualizados_demandado',
@cant_actor as 'actualizados_actor'
END
GO
Depends On
2Used By
No items found