** ********************Inicio de la Solución******************** **
create procedure spGenBK_Consultar_Array
@guia varchar(8000),
@Fecha char(4),
@Prod char(1) ,
@Cliente char(8),
@CodReferenciaFac varchar(4) ='',
@CodReferenciaweb varchar(4) = ''
as
BEGIN
declare @vSql varchar(8000)
set @vSql = 'select
gdn.pro_cod as Producto,
gn.guia_bill_pag_ref as Cliente,
gdn.guia_ano as OrdenAnio,
CASE WHEN GUIA_BILL_PAG_REF = ''00288710'' and gdn.pro_cod = ''NAC''
then isnull(guia_orden_referencial,'''')
else gdn.guia_nro
END as OrdenNro,
CASE WHEN GUIA_BILL_PAG_REF = ''00288710'' and gdn.pro_cod = ''NAC''
then ''''
ELSE isnull(guia_orden_referencial,'''')
END as OrdenNroRef,
gdn.Guia_det_nro_ref as Guia,
convert(varchar, gdn.guia_det_fch_emi, 103) as FechaEmi,
replace(substring(gdn.GUIA_DET_CON_CIA,0,100),'''','''') as Consignatario,
CASE WHEN GUIA_BILL_PAG_REF = ''00288710'' and gdn.pro_cod = ''NAC''
then rtrim(gdn.Guia_det_nro_ref )
ELSE rtrim(gdn.guia_det_con_cuent_refer)
end as Cuenta,
guia_servicio as serviciocod,
ref_cod as ReferenciaCod,
ref_fac_cod as CenCostoCod,
gdd_new_imei as ImeiEntrega,
gdd_dev_imei as ImeiRecojo,
gdd_dev_telf as Telefono,
rtrim(isnull(guia_det_nro_master,'''')) as Master,
gdn.guia_det_id as GuiaDetId
from guia_detalle_nacional as gdn WITH(NOLOCK) '
set @vSql =@vSql+ ' join guia_nacional as gn WITH(NOLOCK)
on gn.empr_cod = gdn.empr_cod
and gn.suc_cod = gdn.suc_cod
and gn.uni_neg_cod = gdn.uni_neg_cod
and gn.pro_cod = gdn.pro_cod
and gn.guia_ano = gdn.guia_ano
and gn.guia_nro = gdn.guia_nro
left join gdn_detalle as det WITH(NOLOCK)
on det.guia_det_id = gdn.guia_det_id
where
gdn.empr_cod = ''00040007''
and gdn.uni_neg_cod = ''SLG''
and YEAR( gdn.guia_det_fch_emi) = '''+@Fecha+'''
and gdn.pro_cod = case '''+@Prod+'''
when ''1'' then ''NAC''
when ''2'' then ''MET''
when ''3'' then gdn.pro_cod
end '
set @vSql =@vSql+ ' and gn.guia_shi_cod = '''+ @Cliente +''' '
set @vSql =@vSql+ ' and rtrim(gdn.Guia_det_nro_ref) in (' + rtrim(ltrim(@guia ))+ ')
and isnull(gn.REF_FAC_COD,'''')=case when '''+@CodReferenciaFac +''' ='''' then isnull(gn.REF_FAC_COD,'''') else '''+@CodReferenciaFac+''' end
and isnull(gdn.REF_COD,'''')=case when '''+ @CodReferenciaweb +''' ='''' then isnull(gdn.REF_COD,'''') else '''+@CodReferenciaweb+''' end '
exec (@vSql)
end
** ********************Fin de la Solución******************** **
tengo un caso. Yo quisiera enviar un array de datos que obtengo desde Un bucle(aquí es donde quisiera saber cómo concatenar correctamente para mandarlo al SP, o quizas alojarlo en un array list y mandarlo al SP.
Ejemplo del SP:
Sp_consultar_detalle
@guia varchar(5000, según sea el caso la cantidad que vaya a
concatenar o recibir),
@año date
As
Select *
From detalle_guias with(nolock)
Where nro_guia IN(@guia)
And fecha_guia = year(@ño)
Llamando al Sp: Exec Sp_cobsultar_detalle (@guia=‘guia1’,’guia2’,etc, @año=2018, etc)--> Es una idea
Que funcione algo así:
select * from GUIA_DETALLE_NACIONAL with (nolock)
where rtrim(Guia_det_nro_ref) in ('1010968487-1','1010968485-2')
En mi aplicación de C# tengo un For que recorre un Excel y obtienes los números de guía , luego llama al SP y es aquí donde no se como concatenar esos números de guía para mandarlo como un parámetro.
Espero puedan ayudarme.
TODO ESTO ES MI Store Procedure REAL, me puedes dar una mano para como modificar con los datos que me recomiendas.
create procedure spGenBK_Consultar_Masivo
@guia varchar(max),
@Fecha char(6),
@Prod char(1) ,
@Cliente char(8),
@CodReferenciaFac varchar(4) ='',
@CodReferenciaweb varchar(4) = ''
as
select
gdn.pro_cod as Producto,
gn.guia_bill_pag_ref as Cliente,
gdn.guia_ano as OrdenAnio,
CASE WHEN GUIA_BILL_PAG_REF = '00288710' and gdn.pro_cod = 'NAC'
then isnull(guia_orden_referencial,'')
else gdn.guia_nro
END as OrdenNro,
CASE WHEN GUIA_BILL_PAG_REF = '00288710' and gdn.pro_cod = 'NAC'
then ''
ELSE isnull(guia_orden_referencial,'')
END as OrdenNroRef,
gdn.Guia_det_nro_ref as Guia,
convert(varchar, gdn.guia_det_fch_emi, 103) as FechaEmi,
replace(substring(gdn.GUIA_DET_CON_CIA,0,100),'''','') as Consignatario,
CASE WHEN GUIA_BILL_PAG_REF = '00288710' and gdn.pro_cod = 'NAC'
then rtrim(gdn.Guia_det_nro_ref )
ELSE rtrim(gdn.guia_det_con_cuent_refer)
end as Cuenta,
guia_servicio as serviciocod,
ref_cod as ReferenciaCod,
ref_fac_cod as CenCostoCod,
gdd_new_imei as ImeiEntrega,
gdd_dev_imei as ImeiRecojo,
gdd_dev_telf as Telefono,
rtrim(isnull(guia_det_nro_master,'')) as Master,
gdn.guia_det_id as GuiaDetId
from guia_detalle_nacional as gdn WITH(NOLOCK)
join guia_nacional as gn WITH(NOLOCK)
on gn.empr_cod = gdn.empr_cod
and gn.suc_cod = gdn.suc_cod
and gn.uni_neg_cod = gdn.uni_neg_cod
and gn.pro_cod = gdn.pro_cod
and gn.guia_ano = gdn.guia_ano
and gn.guia_nro = gdn.guia_nro
left join gdn_detalle as det WITH(NOLOCK)
on det.guia_det_id = gdn.guia_det_id
where
gdn.empr_cod = '00040007'
and gdn.uni_neg_cod = 'SLG'
and rtrim(gdn.Guia_det_nro_ref) in (@guia)
and YEAR( gdn.guia_det_fch_emi) = @Fecha
and gdn.pro_cod = case @Prod
when '1' then 'NAC'
when '2' then 'MET'
when '3' then gdn.pro_cod
end
and gn.guia_shi_cod =@Cliente
and isnull(gn.REF_FAC_COD,'')=case when @CodReferenciaFac='' then isnull(gn.REF_FAC_COD,'') else @CodReferenciaFac end
and isnull(gdn.REF_COD,'')=case when @CodReferenciaweb='' then isnull(gdn.REF_COD,'') else @CodReferenciaweb end