dbo.LN_identificadores

Description

Properties

Name Value
ANSI Nulls ON

True

Quoted Identifier ON

True

Encrypted

False

Execute As
Assembly

Parameters

8
Name Data Type Length Description
@accion varchar 30
@identificador varchar 10
@country_code varchar 2
@activo bit 1
@abreviatura varchar 20
@nombre_identificador varchar 100
@tipo_identificador char 1
@es_pasaporte bit 1

SQL Script

Copy
SET QUOTED_IDENTIFIER, ANSI_NULLS ON
GO
-- Create the stored procedure in the specified schema
CREATE OR ALTER PROCEDURE dbo.LN_identificadores
    @accion VARCHAR(30), -- ALTA,ACTUALIZAR,ESTADO,SELECCIONAR
    @identificador VARCHAR(10),
    @country_code VARCHAR(2)=NULL,
    @activo BIT=0,
    @abreviatura VARCHAR(20)=NULL,
    @nombre_identificador VARCHAR(100)=NULL,
    @tipo_identificador CHAR(1)=NULL,
    @es_pasaporte BIT=0
    -- add more stored procedure parameters here
AS
BEGIN
    DECLARE @v_accion VARCHAR(30) = UPPER(@accion);
    DECLARE @v_country_code VARCHAR(2) = UPPER(@country_code);
    -- actualizar el registro del identificador
    IF ( @v_accion = 'ACTUALIZAR' )
    BEGIN
        UPDATE identificadores SET 
            abreviatura=@abreviatura,
            nombre_identificador=@nombre_identificador,
            tipo_ident=@tipo_identificador,
            es_pasaporte=@es_pasaporte
        WHERE identificador=@identificador;
        --
        RETURN;
    END
    -- alta de nuevo identificador
    IF ( @v_accion = 'ALTA' )
    BEGIN
        INSERT INTO identificadores
        (
            identificador,
            country_code,
            se_usa,
            nombre_identificador,
            abreviatura,
            tipo_ident,
            es_pasaporte
        ) 
        VALUES
        (
            @identificador,
            @v_country_code,
            1,
            @abreviatura,
            @nombre_identificador,
            @tipo_identificador,
            @es_pasaporte
        );
        --
        SELECT 
            identificador,
            country_code,
            abreviatura,
            nombre_identificador,
            se_usa,
            tipo_ident,
            IIF(identificadores.es_pasaporte IS NULL,0,identificadores.es_pasaporte) as es_pasaporte
        FROM identificadores 
        WHERE identificador=@identificador;
        --
        RETURN;
    END
    -- Cambiar el estado del identificador
    IF ( @v_accion = 'ESTADO' )
    BEGIN
        UPDATE identificadores SET se_usa=@activo WHERE identificador=@identificador;
        --
        RETURN;
    END
    -- Obtener los datos de un identificador
    IF ( @v_accion = 'SELECCIONAR' )
    BEGIN
        SELECT 
            identificadores.identificador,            
            identificadores.abreviatura,
            identificadores.nombre_identificador,
            identificadores.se_usa,
            identificadores.tipo_ident,
            identificadores.country_code,
            IIF(identificadores.es_pasaporte IS NULL,0,identificadores.es_pasaporte) as es_pasaporte,
            country.country_name
        FROM identificadores 
        --
        INNER JOIN country ON country.country_code=identificadores.country_code
        --
        WHERE identificadores.identificador=@identificador;
        RETURN;
    END
    -- Obtener los identificadores por pais
    IF ( @v_accion= 'SELECCIONAR_POR_PAIS' )
    BEGIN
        SELECT 
            identificadores.identificador,            
            identificadores.abreviatura,
            identificadores.nombre_identificador,
            identificadores.se_usa,
            identificadores.tipo_ident,
            identificadores.country_code,
            IIF(identificadores.es_pasaporte IS NULL,0,identificadores.es_pasaporte) as es_pasaporte,
            country.country_name
        FROM identificadores
        --
        INNER JOIN country ON country.country_code=identificadores.country_code
        --
        WHERE identificadores.country_code=@v_country_code;
    END

 -- Obtener los identificadores por pais
    IF ( @v_accion= 'SELECCIONAR_POR_PAIS_FILTROS' )
    BEGIN
        SELECT 
            identificadores.identificador,            
            identificadores.abreviatura,
            identificadores.nombre_identificador,
            identificadores.se_usa,
            identificadores.tipo_ident,
            identificadores.country_code,
            IIF(identificadores.es_pasaporte IS NULL,0,identificadores.es_pasaporte) as es_pasaporte,
            country.country_name
        FROM identificadores
        --
        INNER JOIN country ON country.country_code=identificadores.country_code
        --
        WHERE 
            identificadores.country_code=@v_country_code
            AND identificadores.se_usa=@activo
            AND identificadores.tipo_ident=@tipo_identificador
            AND isnull(identificadores.es_pasaporte,0)=@es_pasaporte;
    END

END
GO

Used By

No items found