Description
Properties
| Name | Value |
|---|---|
| ANSI Nulls ON | True |
| Quoted Identifier ON | True |
| Encrypted | False |
| Execute As | |
| Assembly |
Parameters
6| Name | Data Type | Length | Description |
|---|---|---|---|
| @campo_id | varchar | -1 | |
| @valor_numerico | float | 8 | |
| @valor_texto | varchar | -1 | |
| @valor_fecha_srt | varchar | -1 | |
| @respuesta | varchar | -1 | |
| @tipo_doc | int | 4 |
SQL Script
Copy
SET QUOTED_IDENTIFIER, ANSI_NULLS ON
GO
/*
declare @resp varchar(max)
exec [LN_excel_opciones_RSE] 'MEDIO_AMBIENTE' ,null,'J',null,@resp output
select @resp
*/
CREATE OR ALTER PROCEDURE dbo.LN_excel_opciones_RSE
@campo_id varchar(max),
@valor_numerico float,
@valor_texto varchar(max),
@valor_fecha_srt varchar(max),
@respuesta varchar(max) = null output,
@tipo_doc int null
AS
BEGIN
SET NOCOUNT ON;
declare @opciones varchar(max) = null
declare @campo int = NULL
declare @tipo_campo char(1) = ''
declare @respuesta_final varchar(max) = null
declare @item_respuesta tinyint = null
declare @item varchar(max) = null
declare @parte varchar(max) = null
declare @nombre_opcion varchar(max) = null
declare @valor_opcion varchar(max) = null
if (@tipo_doc is null)
select @campo = campo from LN_tipo_doc_campos where campo_id = @campo_id
else
select @campo = campo from LN_tipo_doc_campos where campo_id = @campo_id and tipo_doc = @tipo_doc
if (@campo is not null)
select @opciones = opciones, @tipo_campo = tipo_campo from LN_campos where campo = @campo
if (@tipo_campo in ('B'))
begin
if @valor_numerico = 1 set @respuesta_final = 'SI'
if @valor_numerico = 0 set @respuesta_final = 'NO'
end
if (@tipo_campo in ('M','T','L'))
begin
set @respuesta_final = @valor_texto
end
if (@tipo_campo in ('N'))
begin
set @respuesta_final = convert(varchar,@valor_numerico)
end
if (@tipo_campo in ('D'))
begin
set @respuesta_final = @valor_fecha_srt
end
if (@tipo_campo in ('S','R','C'))
begin
set @respuesta_final = ''
DECLARE c_valores CURSOR FOR
select item from dbo.DelimitedSplit8K(@valor_texto, ',')
OPEN c_valores
FETCH NEXT FROM c_valores INTO @valor_texto
WHILE @@fetch_status = 0
BEGIN
DECLARE c_opciones CURSOR FOR
select * from dbo.DelimitedSplit8K(@opciones, '^')
OPEN c_opciones
FETCH NEXT FROM c_opciones INTO @item, @parte
WHILE @@fetch_status = 0
BEGIN
if @item = 1 set @nombre_opcion = @parte
if @item = 2 set @valor_opcion = @parte
FETCH NEXT FROM c_opciones INTO @item, @parte
END
CLOSE c_opciones
DEALLOCATE c_opciones
DECLARE c_opciones1 CURSOR FOR
select * from dbo.DelimitedSplit8K(@valor_opcion, '|')
OPEN c_opciones1
FETCH NEXT FROM c_opciones1 INTO @item, @parte
WHILE @@fetch_status = 0
BEGIN
if (@parte = @valor_texto) set @item_respuesta = @item
FETCH NEXT FROM c_opciones1 INTO @item, @parte
END
CLOSE c_opciones1
DEALLOCATE c_opciones1
DECLARE c_opciones2 CURSOR FOR
select * from dbo.DelimitedSplit8K(@nombre_opcion, '|')
OPEN c_opciones2
FETCH NEXT FROM c_opciones2 INTO @item, @parte
WHILE @@fetch_status = 0
BEGIN
if (@item = @item_respuesta)
begin
if (@respuesta_final = '')
set @respuesta_final = @parte
else
set @respuesta_final = @respuesta_final + ' --- ' + @parte
end
FETCH NEXT FROM c_opciones2 INTO @item, @parte
END
CLOSE c_opciones2
DEALLOCATE c_opciones2
FETCH NEXT FROM c_valores INTO @valor_texto
END
CLOSE c_valores
DEALLOCATE c_valores
end
set @respuesta = ltrim(rtrim(@respuesta_final))
END
GO
GO
/*
declare @resp varchar(max)
exec [LN_excel_opciones_RSE] 'MEDIO_AMBIENTE' ,null,'J',null,@resp output
select @resp
*/
CREATE OR ALTER PROCEDURE dbo.LN_excel_opciones_RSE
@campo_id varchar(max),
@valor_numerico float,
@valor_texto varchar(max),
@valor_fecha_srt varchar(max),
@respuesta varchar(max) = null output,
@tipo_doc int null
AS
BEGIN
SET NOCOUNT ON;
declare @opciones varchar(max) = null
declare @campo int = NULL
declare @tipo_campo char(1) = ''
declare @respuesta_final varchar(max) = null
declare @item_respuesta tinyint = null
declare @item varchar(max) = null
declare @parte varchar(max) = null
declare @nombre_opcion varchar(max) = null
declare @valor_opcion varchar(max) = null
if (@tipo_doc is null)
select @campo = campo from LN_tipo_doc_campos where campo_id = @campo_id
else
select @campo = campo from LN_tipo_doc_campos where campo_id = @campo_id and tipo_doc = @tipo_doc
if (@campo is not null)
select @opciones = opciones, @tipo_campo = tipo_campo from LN_campos where campo = @campo
if (@tipo_campo in ('B'))
begin
if @valor_numerico = 1 set @respuesta_final = 'SI'
if @valor_numerico = 0 set @respuesta_final = 'NO'
end
if (@tipo_campo in ('M','T','L'))
begin
set @respuesta_final = @valor_texto
end
if (@tipo_campo in ('N'))
begin
set @respuesta_final = convert(varchar,@valor_numerico)
end
if (@tipo_campo in ('D'))
begin
set @respuesta_final = @valor_fecha_srt
end
if (@tipo_campo in ('S','R','C'))
begin
set @respuesta_final = ''
DECLARE c_valores CURSOR FOR
select item from dbo.DelimitedSplit8K(@valor_texto, ',')
OPEN c_valores
FETCH NEXT FROM c_valores INTO @valor_texto
WHILE @@fetch_status = 0
BEGIN
DECLARE c_opciones CURSOR FOR
select * from dbo.DelimitedSplit8K(@opciones, '^')
OPEN c_opciones
FETCH NEXT FROM c_opciones INTO @item, @parte
WHILE @@fetch_status = 0
BEGIN
if @item = 1 set @nombre_opcion = @parte
if @item = 2 set @valor_opcion = @parte
FETCH NEXT FROM c_opciones INTO @item, @parte
END
CLOSE c_opciones
DEALLOCATE c_opciones
DECLARE c_opciones1 CURSOR FOR
select * from dbo.DelimitedSplit8K(@valor_opcion, '|')
OPEN c_opciones1
FETCH NEXT FROM c_opciones1 INTO @item, @parte
WHILE @@fetch_status = 0
BEGIN
if (@parte = @valor_texto) set @item_respuesta = @item
FETCH NEXT FROM c_opciones1 INTO @item, @parte
END
CLOSE c_opciones1
DEALLOCATE c_opciones1
DECLARE c_opciones2 CURSOR FOR
select * from dbo.DelimitedSplit8K(@nombre_opcion, '|')
OPEN c_opciones2
FETCH NEXT FROM c_opciones2 INTO @item, @parte
WHILE @@fetch_status = 0
BEGIN
if (@item = @item_respuesta)
begin
if (@respuesta_final = '')
set @respuesta_final = @parte
else
set @respuesta_final = @respuesta_final + ' --- ' + @parte
end
FETCH NEXT FROM c_opciones2 INTO @item, @parte
END
CLOSE c_opciones2
DEALLOCATE c_opciones2
FETCH NEXT FROM c_valores INTO @valor_texto
END
CLOSE c_valores
DEALLOCATE c_valores
end
set @respuesta = ltrim(rtrim(@respuesta_final))
END
GO