cancel
Showing results for 
Search instead for 
Did you mean: 

Query de Asientos contables

Former Member
0 Kudos

Buen día a todos! Me encargaron hacer una consulta para ver los asientos contables, por quienes fueron hecho y otros campos. Me pidieron el campo Footer de los diferentes documentos, saque primero el de las Facturas de clientes (tabla OINV) y sin problema pero ahora me piden el footer de Ordenes de compra,Entrada de mercancías, Factura de proveedores, entre otros. Mi consulta es la siguiente


SELECT je1.TransId , je.baseref 'Num. Origen',je.Ref1 'Referencia',je.RefDate  ,je.createdate 'Fecha de sistema',acc.AcctCode 'Numero Cuenta',acc.AcctName'Nombre Cuenta' ,

  je.Memo'Transaccion' ,je1.Debit'Debito' ,je1.Credit'Credito',

  Quien_lo_creo = CASE je.usersign

  when 1 then 'Manager'

  when 2 then 'B1i'

  when 3 then 'Jesus Alberto Anderson Olivas'

  when 4 then 'Alba Nidia Arredondo Zubiran'

  when 5 then 'Nancy Maldonado Morales'

  when 6 then 'Flor Nayeli Delgado Delgado'

  when 7 then 'Perla de Jesus Irigoyen Diaz'

  when 8 then 'Flor Nayeli Delgado Delgado'

  when 9 then 'Juan Antonio Ontiveros Gardea'

  when 10 then 'Claudia Angelica Olivas Grijalva'

  when 11 then 'Perla'

  when 12 then 'Rocio Rodriguez'

  end,

  Quien_lo_modifico = CASE je.usersign2

  when 1 then 'Manager'

  when 2 then 'B1i'

  when 3 then 'Jesus Alberto Anderson Olivas'

  when 4 then 'Alba Nidia Arredondo Zubiran'

  when 5 then 'Nancy Maldonado Morales'

  when 6 then 'Flor Nayeli Delgado Delgado'

  when 7 then 'Perla de Jesus Irigoyen Diaz'

  when 8 then 'Flor Nayeli Delgado Delgado'

  when 9 then 'Juan Antonio Ontiveros Gardea'

  when 10 then 'Claudia Angelica Olivas Grijalva'

  when 11 then 'Perla'

  when 12 then 'Rocio Rodriguez'

  end,

  OI.Footer as 'Footer Fact. Clientes'

  FROM JDT1 as je1

left join OPRC as prc on je1.ProfitCode = prc.PrcCode

left join OPRC as prc2 on je1.OcrCode2 = prc2.PrcCode

left join OPRC as prc3 on je1.OcrCode3 = prc3.PrcCode

left join OPRC as prc4 on je1.OcrCode4 = prc4.PrcCode

left join OPRC as prc5 on je1.OcrCode5 = prc5.PrcCode

inner join OACT as acc on je1.Account = acc.AcctCode

join OJDT as je on je1.TransId = je.TransId

join OINV OI on OI.TransId=je1.TransId

join OPOR OC on OC.TransId=je1.TransId

join ousr b on je.usersign=b.internal_K 

order by 4

Pensé que haciendo un join parecido al de  join OINV OI on OI.TransId=je1.TransId pero con la tabla OPOR en lugar de lo OINV podría funcionar pero no es así, porque los 2 joins hacen que ningún registro cumpla con los 2 joins. Conocen alguna forma de tomar esos campos? por medio subconsultas o un join diferente o algo? Lo agradecería mucho!!

Gracias y saludos!

Accepted Solutions (1)

Accepted Solutions (1)

Former Member
0 Kudos

Intenta así:

SELECT je1.TransId , je.baseref 'Num. Origen',je.Ref1 'Referencia',je.RefDate  ,je.createdate 'Fecha de sistema',acc.AcctCode 'Numero Cuenta',acc.AcctName'Nombre Cuenta' ,

  je.Memo'Transaccion' ,je1.Debit'Debito' ,je1.Credit'Credito',

  Quien_lo_creo = CASE je.usersign

  when 1 then 'Manager'

  when 2 then 'B1i'

  when 3 then 'Jesus Alberto Anderson Olivas'

  when 4 then 'Alba Nidia Arredondo Zubiran'

  when 5 then 'Nancy Maldonado Morales'

  when 6 then 'Flor Nayeli Delgado Delgado'

  when 7 then 'Perla de Jesus Irigoyen Diaz'

  when 8 then 'Flor Nayeli Delgado Delgado'

  when 9 then 'Juan Antonio Ontiveros Gardea'

  when 10 then 'Claudia Angelica Olivas Grijalva'

  when 11 then 'Perla'

  when 12 then 'Rocio Rodriguez'

  end,

  Quien_lo_modifico = CASE je.usersign2

  when 1 then 'Manager'

  when 2 then 'B1i'

  when 3 then 'Jesus Alberto Anderson Olivas'

  when 4 then 'Alba Nidia Arredondo Zubiran'

  when 5 then 'Nancy Maldonado Morales'

  when 6 then 'Flor Nayeli Delgado Delgado'

  when 7 then 'Perla de Jesus Irigoyen Diaz'

  when 8 then 'Flor Nayeli Delgado Delgado'

  when 9 then 'Juan Antonio Ontiveros Gardea'

  when 10 then 'Claudia Angelica Olivas Grijalva'

  when 11 then 'Perla'

  when 12 then 'Rocio Rodriguez'

  end,

  isnull(OI.Footer,'') + isnull(OC.Footer,'') as 'Footer Document

/* o intenta con las siguientes dos líneas, no indicas si lo necesitas separado o en una columna:

OI.Footer 'Footer Factura clientes'

OC.Footer 'Footer OC' */

  FROM JDT1 as je1

left join OPRC as prc on je1.ProfitCode = prc.PrcCode

left join OPRC as prc2 on je1.OcrCode2 = prc2.PrcCode

left join OPRC as prc3 on je1.OcrCode3 = prc3.PrcCode

left join OPRC as prc4 on je1.OcrCode4 = prc4.PrcCode

left join OPRC as prc5 on je1.OcrCode5 = prc5.PrcCode

inner join OACT as acc on je1.Account = acc.AcctCode

join OJDT as je on je1.TransId = je.TransId

left join OINV OI on OI.TransId=je1.TransId

left join OPOR OC on OC.TransId=je1.TransId

join ousr b on je.usersign=b.internal_K

order by 4

Sólo agregarle los LEFT JOINs q te hagan falta de los otros tipos de documento...

Saludos y suerte

Former Member
0 Kudos

Al final me pidieron algo distinto, pero si me sirvió tu indicación.

Gracias y saludos! 

Answers (0)