dbo.backend_obtener_total_integrantes_no_asignados_SC

Description

Properties

Name Value
ANSI Nulls ON

True

Quoted Identifier ON

True

Encrypted

False

Execute As
Assembly

Parameters

1
Name Data Type Length Description
@p_letra varchar 1

SQL Script

Copy
SET QUOTED_IDENTIFIER, ANSI_NULLS ON
GO

-- =============================================
-- Author: <Samuel Gonzalez>
-- Create date: <13 Sep 2017>
-- Description: <Obtener TOTAL de sociedades asignadas con integrantes no asignadass en Sociedades Constituciones para procesar por ABM>
-- =============================================
CREATE OR ALTER PROCEDURE  dbo.backend_obtener_total_integrantes_no_asignados_SC
@p_letra varchar(1)
 -- Add the parameters for the stored procedure here

AS
BEGIN
 SET NOCOUNT ON;
 
 declare @a int; declare @b int
    IF ((@p_letra IS NOT NULL) AND (@p_letra != ''))
    BEGIN

        SELECT COUNT(*) AS cantidad FROM (
            SELECT
                sc.razon_social           as soc_nombre,
                sc.domicilio_sociedad     as soc_domicilio,
                sc.localidad_sociedad     as soc_localidad,
                sc.provincia_sociedad     as soc_provincia,
                sc.capita_social          as soc_capital_social,
                sc.titulo                 as pub_titulo,
                CAST(sc.objeto AS VARCHAR)as pub_objeto,
                sc.fuente                 as pub_fuente,
                sc.tipo_publicacion       as pub_tipo_1,
                sc.tipo_publicacion_2     as pub_tipo_2,
                sc.codigo_archivo         as pub_codigo,
                sc.nombre_file            as pub_archivo,
             sc.fecha_publicacion      as pub_fecha,
                sc.duracion               as pub_duracion,
                CAST(sc.contenido_archivo AS VARCHAR) as pub_contenido,
                0 as es_sociedad,
                null as procesado
            FROM sociedades_constituciones sc
            INNER JOIN asignacion_cuits_sociedades_constituciones_log a
            ON (sc.id_fide = a.id_sociedades_constituciones) AND (a.es_sociedad = 0) AND (a.procesado_2 IS NULL)
            INNER JOIN (
                select scx.razon_social, scx.nombre_file, scx.codigo_archivo from sociedades_constituciones scx 
                inner join asignacion_cuits_sociedades_constituciones_log ax on (scx.id_fide = ax.id_sociedades_constituciones)
                where (es_sociedad = 1) and (procesado_2 = 1)
            ) zz ON (sc.razon_social = zz.razon_social) AND (sc.nombre_file = zz.nombre_file) AND (sc.codigo_archivo = zz.codigo_archivo)
            WHERE (sc.flag_int = 'B') 
            AND (sc.cuit_int IS NULL or sc.cuit_int = '')
            AND (sc.razon_social like @p_letra +'%')
            -- EN TEORIA, SOCIEDADES ENCONTRADAS, QUE POSEEN INTEGRANTES NO ENCONTRADOS POR MULTIPLICIDAD

            UNION

            SELECT
                sc.razon_social           as soc_nombre,
                sc.domicilio_sociedad     as soc_domicilio,
                sc.localidad_sociedad     as soc_localidad,
                sc.provincia_sociedad     as soc_provincia,
                sc.capita_social          as soc_capital_social,
                sc.titulo                 as pub_titulo,
                CAST(sc.objeto AS VARCHAR)as pub_objeto,
                sc.fuente                 as pub_fuente,
                sc.tipo_publicacion       as pub_tipo_1,
                sc.tipo_publicacion_2     as pub_tipo_2,
                sc.codigo_archivo         as pub_codigo,
                sc.nombre_file            as pub_archivo,
             sc.fecha_publicacion      as pub_fecha,
                sc.duracion               as pub_duracion,
                CAST(sc.contenido_archivo AS VARCHAR) as pub_contenido,
                0 as es_sociedad,
                null as procesado
            FROM sociedades_constituciones sc
            INNER JOIN asignacion_cuits_sociedades_constituciones_log a
            ON (sc.id_fide = a.id_sociedades_constituciones) AND (a.es_sociedad = 0) AND (a.procesado_2 = 0)
            INNER JOIN (
                select scx.razon_social, scx.nombre_file, scx.codigo_archivo from sociedades_constituciones scx 
                inner join asignacion_cuits_sociedades_constituciones_log ax on (scx.id_fide = ax.id_sociedades_constituciones)
                where (es_sociedad = 1) and (procesado_2 = 1)
            ) zz ON (sc.razon_social = zz.razon_social) AND (sc.nombre_file = zz.nombre_file) AND (sc.codigo_archivo = zz.codigo_archivo)
            WHERE (sc.flag_int = 'B') 
            AND (sc.cuit_int IS NULL or sc.cuit_int = '')
            AND (sc.razon_social like @p_letra +'%')
            -- EN TEORIA, SOCIEDADES ENCONTRADAS, QUE POSEEN INTEGRANTES NO ENCONTRADOS POR MULTIPLICIDAD
        ) totales
    END
    ELSE
    BEGIN
        SELECT COUNT(*) AS cantidad FROM (
            SELECT
                sc.razon_social           as soc_nombre,
                sc.domicilio_sociedad     as soc_domicilio,
                sc.localidad_sociedad     as soc_localidad,
                sc.provincia_sociedad     as soc_provincia,
                sc.capita_social          as soc_capital_social,
                sc.titulo                 as pub_titulo,
                CAST(sc.objeto AS VARCHAR)as pub_objeto,
                sc.fuente                 as pub_fuente,
                sc.tipo_publicacion       as pub_tipo_1,
                sc.tipo_publicacion_2     as pub_tipo_2,
                sc.codigo_archivo         as pub_codigo,
                sc.nombre_file            as pub_archivo,
             sc.fecha_publicacion      as pub_fecha,
                sc.duracion               as pub_duracion,
                CAST(sc.contenido_archivo AS VARCHAR) as pub_contenido,
                0 as es_sociedad,
                null as procesado
            FROM sociedades_constituciones sc
            INNER JOIN asignacion_cuits_sociedades_constituciones_log a
            ON (sc.id_fide = a.id_sociedades_constituciones) AND (a.es_sociedad = 0) AND (a.procesado_2 IS NULL)
            INNER JOIN (
                select scx.razon_social, scx.nombre_file, scx.codigo_archivo from sociedades_constituciones scx 
                inner join asignacion_cuits_sociedades_constituciones_log ax on (scx.id_fide = ax.id_sociedades_constituciones)
                where (es_sociedad = 1) and (procesado_2 = 1)
            ) zz ON (sc.razon_social = zz.razon_social) AND (sc.nombre_file = zz.nombre_file) AND (sc.codigo_archivo = zz.codigo_archivo)
            WHERE (sc.flag_int = 'B') 
            AND (sc.cuit_int IS NULL or sc.cuit_int = '')
            -- EN TEORIA, SOCIEDADES ENCONTRADAS, QUE POSEEN INTEGRANTES NO ENCONTRADOS POR MULTIPLICIDAD

            UNION

            SELECT
                sc.razon_social           as soc_nombre,
                sc.domicilio_sociedad     as soc_domicilio,
                sc.localidad_sociedad     as soc_localidad,
                sc.provincia_sociedad     as soc_provincia,
                sc.capita_social          as soc_capital_social,
                sc.titulo                 as pub_titulo,
                CAST(sc.objeto AS VARCHAR)as pub_objeto,
                sc.fuente                 as pub_fuente,
                sc.tipo_publicacion       as pub_tipo_1,
                sc.tipo_publicacion_2     as pub_tipo_2,
                sc.codigo_archivo         as pub_codigo,
                sc.nombre_file            as pub_archivo,
             sc.fecha_publicacion      as pub_fecha,
                sc.duracion               as pub_duracion,
                CAST(sc.contenido_archivo AS VARCHAR) as pub_contenido,
                0 as es_sociedad,
                null as procesado
            FROM sociedades_constituciones sc
            INNER JOIN asignacion_cuits_sociedades_constituciones_log a
            ON (sc.id_fide = a.id_sociedades_constituciones) AND (a.es_sociedad = 0) AND (a.procesado_2 = 0)
            INNER JOIN (
                select scx.razon_social, scx.nombre_file, scx.codigo_archivo from sociedades_constituciones scx 
                inner join asignacion_cuits_sociedades_constituciones_log ax on (scx.id_fide = ax.id_sociedades_constituciones)
                where (es_sociedad = 1) and (procesado_2 = 1)
            ) zz ON (sc.razon_social = zz.razon_social) AND (sc.nombre_file = zz.nombre_file) AND (sc.codigo_archivo = zz.codigo_archivo)
            WHERE (sc.flag_int = 'B') 
            AND (sc.cuit_int IS NULL or sc.cuit_int = '')
            -- EN TEORIA, SOCIEDADES ENCONTRADAS, QUE POSEEN INTEGRANTES NO ENCONTRADOS POR MULTIPLICIDAD
        ) totales
    END
END

GO