cancel
Showing results for 
Search instead for 
Did you mean: 

Error Tabla Vacía

former_member263548
Participant
0 Kudos

Buenos días, tengo un error con un query el cual no me muestra todo el consecutivo de ODS, revisando veo que si la tabla SCL2 no contiene datos, no me muestra esa ODS, les agradezco sus comentarios.

Esta es la consulta que tengo:

SET Language Español

SELECT

  T0.[callID]'# Llamada',

  T1.[U_TipoServicio]'Tipo Servicio',

  T3.[Name]'Status',

  T0.[Subject]'Asunto',

  T0.[customer]'Código',

  T0.[custmrName]'Cliente',

  T6.[descript]'Zona',

  T0.[internalSN]'# Serie',

  T0.[itemCode]'Código',

  T0.[itemName]'Descripción',

  T0.[createDate]'Fecha Creación',

  DATENAME(MM,T0.[createDate])'Mes',

  T0.[createTime]'Hora Creación',

  'Técnico Asignado'=Case T1.[U_Tecnico1]

  when '01' then 'Antonio Medina'

  when '02' then 'Christian Alvarado'

  when '03' then 'Freddy Varela'

  when '04' then 'Jeffry Monge'

  when '05' then 'Leyner Acuña'

  when '06' then 'Luis Arguedas'

  when '07' then 'Kenneth Villalta'

  when '08' then 'Kevin Uribe'

  when '09' then 'Alexander Guzman'

  else 'Agregar en Query' end, 

  T1.[Recontact]'Fecha Servicio',

  T1.[BeginTime]'Hora Inicio',

  T1.[ENDTime]'Hora Fin',

  T1.[Duration]'Duración',

  'Tipo Tarea'=Case T1.[U_TIP_TAREA]

  when '01' then 'Ajuste altura carro'

  when '02' then 'Ambiente equipo sin aire'

  when '03' then 'Archivos corruptos'

  when '04' then 'Bomba dañada'

  when '05' then 'Cabezal tapado o dañado'

  when '06' then 'Cables dañados'

  when '07' then 'Cambio de tinta'

  when '08' then 'Capping dañado'

  when '09' then 'Damper dañado'

  when '10' then 'Descalibrada'

  when '11' then 'Ductos de tinta bloqueado'

  when '12' then 'Estática en material'

  when '13' then 'Fibra optica dañada'

  when '14' then 'Fuente dañada'

  when '15' then 'Instalación'

  when '16' then 'Instalación de código tinta'

  when '17' then 'Limpieza'

  when '18' then 'Mantenimiento programado'

  when '19' then 'No tiene perfil'

  when '20' then 'Problema material'

  when '21' then 'Problema operador'

  when '22' then 'Problemas de alimentación'

  when '23' then 'Problemas de tinta'

  when '24' then 'Problemas SO o PC'

  when '25' then 'Revisar local'

  when '26' then 'Subtanques dañados'

  when '27' then 'UPS dañada'

  when '28' then 'USB dañada'

  when '29' then 'Visita cortesía'

  else 'Agregar en Query'

  end,

'Trabajo Realizar'=Case T1.[U_Tipo_Mant]

  when '01' then 'Arruga en el material'

  when '02' then 'Cambio de tintas'

  when '03' then 'Derrame de tinta'

  when '04' then 'Error en pantalla'

  when '05' then 'Imprime diferente tamaño'

  when '06' then 'Imprime en blanco'

  when '07' then 'Imprime lento'

  when '08' then 'Instalación'

  when '09' then 'Mantenimiento preventivo'

  when '10' then 'No corta'

  when '11' then 'No enciende'

  when '12' then 'No imprime'

  when '13' then 'Perfilar'

  when '14' then 'Problemas abanicos o calentadores'

  when '15' then 'Problemas de calidad'

  when '16' then 'Problemas de Software'

  when '17' then 'Requiere código de tinta'

  when '18' then 'Revisión general'

  when '19' then 'Ruido'

  when '20' then 'Se agota el color'

  when '21' then 'Supervisión'

  when '22' then 'Traslado'

  else 'Agregar en Query'

  end,

  T2.[ItemCode]'Artículo',

  T2.[ItemName]'Descripción',

  T4.[AvgPrice]'Costo',

  T2.[Delivered]'Cant. Entregada',

  T2.[QtyToInv]'Cant. Facturada'

FROM

  OSCL T0

  INNER JOIN OCLG T1 on T0.[callID]=T1.[parentId]

  INNER JOIN SCL2 T2 ON T0.[callID] = T2.[SrcvCallID]

  INNER JOIN OSCS T3 ON T0.[status] = T3.[statusID]

  INNER JOIN OITW T4 ON T2.[itemCode] = T4.[ItemCode]

  INNER JOIN OCRD T5 ON T0.[customer] = T5.[CardCode]

  INNER JOIN OTER T6 ON T5.[Territory] = T6.[territryID]

WHERE

  T0.[createDate]>=[%0] AND T0.[createDate]<=[%1] AND T4.[WHSCODE]='01'

Accepted Solutions (0)

Answers (2)

Answers (2)

former_member285534
Active Participant
0 Kudos

Hola Oscar,

Como sabemos, en SQL un JOIN une los registros de dos tablas que cumplen una o varias condiciones (comúnmente condiciones de igualdad).  Cuando el JOIN es de tipo INNER el query descarta todos los registros que no cumplen estas condiciones.

Por ello si la tabla SCL2 no contiene ningún registro cuyo SrcvCallID coincide con el callID de OSCL, el query está perdiendo algunos registros que por lo que leo esperarías obtener.

La solución es cambiar esta línea:

INNER JOIN SCL2 T2 ON T0.[callID] = T2.[SrcvCallID]


a


LEFT JOIN SCL2 T2 ON T0.[callID] = T2.[SrcvCallID]

El LEFT JOIN conserva las filas que va produciendo el query aún cuando no se cumplen las condiciones de join.  Con ello ya no perderás algunos callID's.  Espera, sin embargo, que los campos que corresponden a la tabla SCL2 estén vacíos (nulos) en aquellos registros que no hicieron match.

Saludos,

Fernando

former_member263548
Participant
0 Kudos

Hola Fernando, muchas gracias por tu tiempo, voy a revisar y te comento.

Saludos,

Oscar

gerardo_mendez
Active Contributor
0 Kudos

Hola Oscar.

Si alguna de tus tablas pueda o no contener registros cambia el Inner Join por un Left Join.

Prueba y nos comentas.

former_member263548
Participant
0 Kudos

Hola Gerardo, intenté utilizando Left Join pero igual no me muestra la cantidad de líneas que debería.