dbo.LN_indicadores_opciones

Description

Properties

Name Value
ANSI Nulls ON

True

Quoted Identifier ON

True

Encrypted

False

Execute As
Assembly

Parameters

3
Name Data Type Length Description
@p_indicador int 4
@p_valor varchar -1
@detalle varchar -1

SQL Script

Copy
SET QUOTED_IDENTIFIER, ANSI_NULLS ON
GO
/*
declare @valores varchar(max) = (select item from dbo.DelimitedSplit8K((select opciones from ln_indicadores where indicador = 417), '^') where ItemNumber = 1)
declare @opciones varchar(max) = (select item from dbo.DelimitedSplit8K((select opciones from ln_indicadores where indicador = 417), '^') where ItemNumber = 2)

select * from dbo.DelimitedSplit8K( @valores,'|')
select * from dbo.DelimitedSplit8K( @opciones,'|')

DECLARE @detalle varchar(max) = null
EXEC [dbo].[LN_indicadores_opciones] 417,'B', @detalle output
select @detalle as detalle 

*/



CREATE OR ALTER PROCEDURE dbo.LN_indicadores_opciones 
  @p_indicador int, 
  @p_valor varchar(max) = null, 
  @detalle varchar(max) = null output 
AS
BEGIN
 SET NOCOUNT ON;

 declare @opciones varchar(max) = null 
 set @opciones = (select opciones from LN_indicadores where indicador = @p_indicador) 
 if (@opciones is null) begin 
  set @detalle = null 
  return 
 end 

 declare @valor  varchar(max) = null
 declare @opcion varchar(max) = null

 set @valor = (select item from dbo.DelimitedSplit8K(@opciones, '^') where ItemNumber = 1)
 set @opcion = (select item from dbo.DelimitedSplit8K(@opciones, '^') where ItemNumber = 2)

 if (@p_valor is not null) 
 begin 
  select @detalle = item from dbo.DelimitedSplit8K( @valor,'|')
  where ItemNumber = (
  select ItemNumber from dbo.DelimitedSplit8K( @opcion,'|') where item = @p_valor) 
 end 
 
END 
GO