on 03-24-2015 11:33 PM
HOLA FORO SAP,
NECESITO DE SU APOYO PARA CONTAR CON EL CICLO DE LOS NUMEROS DE LOS DOCUMENTOS DE:
Orden de Venta, Entregas y Facturas
En cualquier caso de existir:
Orden de Venta -> Entregas -> Facturas
Orden de Venta -> Facturas
SOLO NECESITO LOS NUMEROS, SE QUE ESTAN EN EL CAMPO COMMENTS DE CADA DOCUMENTO. PERO LOS USUARIOS ESCRIBEN MUCHAS COSAS AHI Y ES DIFICIL MOSTRAR ESOS CAMPOS POR TODO EL TEXTO EXTRA.
DE DONDE PODRIA OBTENER ESA CADENA EN CADA CASO?
GRACIAS
Buenas
Prueba este código:
declare
@str varchar(200)
,@cuenta tinyint
,@numeros varchar(100)
set @str='Basado en pedido 1234 . comentario del usuario...etc'
set @numeros=''
set @cuenta=1
while (@cuenta < 200)
begin
if substring(@str, @cuenta,1) in ('0','1','2','3','4','5','6','7','8','9')
set @numeros = @numeros + substring(@str, @cuenta,1)
set @cuenta=@cuenta+1
end
select @numeros
En la variable @str debes colocar el comentario del documento.
Saludos
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Felipe,
Te consulto porque no he logrado insertar tu código en mi consulta. Solo necesito que el campo de T0.Comments muestre el resultado de tu consulta, agradeceria mucho tu apoyo.
Mil Gracias
Mi consulta:
Select distinct T0.DocNum as 'FACTURA',T0.Comments as 'No Documentos',Convert(char(10),t0.DocDate, 103)as 'FECHA FACTURA'
from OINV T0
Para incluirlo debes crear el código como función
create function Devolver_numeros(@str varchar(200))
returns varchar(100)
as begin
declare
@cuenta tinyint
,@numeros varchar(100)
set @numeros=''
set @cuenta=1
while (@cuenta < 200)
begin
if substring(@str, @cuenta,1) in ('0','1','2','3','4','5','6','7','8','9')
set @numeros = @numeros + substring(@str, @cuenta,1)
set @cuenta=@cuenta+1
end
return @numeros
end
go
Luego agregarlo a tu query
Select distinct T0.DocNum as 'FACTURA',dbo.Devolver_numeros(T0.Comments) as 'No Documentos',Convert(char(10),t0.DocDate, 103)as 'FECHA FACTURA'
from OINV T0
Saludos
FELIPE BUEN DIA,
UNA DISCULPA CON RESPECTO A ESTE TEMA CUANDO SUBO MI FUNCION A SAP EN QUERY MANAGER ME EMITE ALGUNOS ERRORES.
TE ADJUNTO MI QUERY PARA TU APOYO POR FAVOR, MUCHAS GRACIAS
ALTER Function Numeros(@str varchar(200))
returns varchar(100)
as begin
declare
@cuenta tinyint
,@numeros varchar(100)
,@num int
set @numeros = ''
set @cuenta = 1
set @num = 0
while (@cuenta < 200)
begin
if substring(@str, @cuenta,1) in ('0','1','2','3','4','5','6','7','8','9')
set @numeros = @numeros + substring(@str, @cuenta,1)
set @cuenta=@cuenta+1
end
return @numeros
end
go
Select
distinct T0.DocNum as 'ENTREGAS',
(dbo.Numeros(SUBSTRING(T0.Comments,(CHARINDEX('Pedidos',T0.Comments)+19),5))) +
(dbo.Numeros(SUBSTRING(T0.Comments,(CHARINDEX('Sales',T0.Comments)+13),5))) as 'PEDIDOS',
Convert(char(10),t0.DocDate, 103)as 'FECHA ENTREGA',
T0.Comments as 'COMENTARIOS',
T0.U_logentrega AS 'LOGISTICA ENTREGA',
T0.U_fechaEmbarqueMHO AS 'FECHA EMBARQUE',
T0.U_noGuia AS 'NO. GUIA',
Case T0.U_destino
when '01' then 'EATON' when '02' then 'FORT WAYNE' when '03' then 'SHREVEPORT' when '04' then 'MIAMI' when '05' then 'MEXICO'
when '06' then 'EDO.MEXICO' when '07' then 'GUADALAJARA' when '08' then 'SPRINGFIELD' when '09' then 'MONTERREY' when '10' then 'PUEBLA'
when '100' then 'SPARTANBURG' when '101' then 'TULARE' when '102' then 'FT.LAUDERDALE' when '103' then 'CRESTON' when '104' then 'BURLINGTON'
when '105' then 'ELGIN' when '106' then 'LINIER BEAUCE' when '107' then 'NINGBO' when '108' then 'GRIFFIN' when '109' then 'FAIRFAX'
when '11' then 'VERNON HILLS' when '110' then 'MOORESVILLE'
end as 'DESTINO',
Case T0.U_transportista
when '00' then 'CLIENTE RECOJE EN OFNA'
when '01' then 'CAMIONETA MHO'
when '02' then 'CAMIONETA SFT'
when '03' then 'CAMIONETA Marin'
when '04' then 'PAQ. EXPRESS'
when '05' then 'FLETES GDL-MERIDA'
when '06' then 'EASO CONSOLIDADO'
when '07' then 'TRANSPORTES CALAFIA'
when '08' then 'TRANSPORTES CULIACAN'
when '09' then 'TRANSPORTES 3 GUERRAS'
when '10' then 'JULIAN DE OBREGON'
when '11' then 'EASO MTY'
when '12' then 'EASO GDL'
when '13' then 'EASO MEX'
when '14' then 'TRANSPORTES ALMEX'
when '15' then 'DHL'
when '16' then 'AEROMEXPRESS'
when '17' then 'ESTAFETA'
when '18' then 'TRANSP UNIDOS TAMPIQUENOS'
when '19' then 'REDPACK'
when '20' then 'TRANSP UNIDOS TAMPIQUENOS'
when '21' then 'AGENTE ADUANAL'
when '22' then 'INNOVATIVOS'
when '23' then 'CAMION COMPLETO'
when '24' then 'ESTRELLA BLANCA'
when '25' then 'TRANSP MERCURIO'
when '26' then 'TRANSP CASTORES'
when '27' then 'EXPRESS DE OCC MERCURIO'
when '28' then 'TRANSP DE CARGA PROGRESO'
when '29' then 'TRANSP SANCHEZ'
when '30' then 'TRANSP POTOSINOS'
when '31' then 'TRANSP CASTORES BAJA'
when '32' then 'LINEAS UNIDAS DEL SUR'
when '33' then 'TRANSP GRUPO NEZA'
when '34' then 'TRANSP ESGADI'
when '35' then 'SIMCS SA DE CV'
when '36' then 'FERNANDO HERNANDEZ'
when '37' then 'AUTOBUSES VALLARTA PLUS'
when '39' then 'MULTIPACK'
when '40' then 'PEGASO'
when '41' then 'PAQUETE EXPRESS'
when '42' then 'ESGADI LOGISTICS'
when '43' then 'UPS'
when '44' then 'FEDEX'
when '45' then 'ETN'
when '46' then 'TRES GUERRAS'
when '47' then 'PMM'
when '48' then 'PRIMERA PLUS'
when '49' then 'ABC AEROLINEAS MX'
when '50' then 'SOUTHEASTERN FREIGHT LINES'
when '51' then 'ENTREGA HELIO MARES'
when '52' then 'FEDEX FREIGHT'
when '53' then 'CASTORES'
when '54' then 'ADUANA'
when '55' then 'MOSTRADOR'
when '56' then 'ENTREGA EN TIENDA'
when '57' then 'SHENKER'
end as 'TRANSPORTISTA'
From ODLN T0
where (T0.DocDate >= '01/01/2010' and t0.DocDate <= '12/31/2015') and (t0.DocStatus = 'O')
Order by T0.DocNum
FELIPE MUCHAS GRACIAS POR TU APORTACION!!
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
User | Count |
---|---|
98 | |
11 | |
11 | |
6 | |
6 | |
4 | |
4 | |
3 | |
3 | |
3 |
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.