tengo un problema al ejecutar una sentencia de una vista en SQL Server. El problema es que cuando hago una relación con otra tabla para añadir otro campo a la consulta, no me devuelve nada. Con esta sentencia, me devuelve todos los campos menos uno:
SELECT CASE WHEN _CPRManufacturingOrder_Custom.Mano = 1 THEN 'I' WHEN _CPRManufacturingOrder_Custom.Mano = 2 THEN 'D' ELSE '' END AS datvar1,
dbo.FACOrderLineSL.Quantity AS envact, dbo._CPRManufacturingOrder_Custom.Ancho AS datvar4, dbo._CPRManufacturingOrder_Custom.Alto AS datvar5,
dbo.FACOrderLineSL.CodCompany AS codemp, dbo.FACInvoicingTypeSL.CodInvoicingType AS tipcont, dbo.FACOrderSL.CodOrder AS numped,
dbo.FACOrderLineSL.IDOrderLine AS numlin, dbo.CPRManufacturingOrder.InternalCode AS numalb, dbo._CPRManufacturingOrder_Custom.Fondo AS datvar6,
YEAR(dbo.CPRManufacturingOrder.PlannedEndDate) AS AÑO, dbo._CPRManufacturingOrder_Custom.ZonaEnvio AS ENVIO,
dbo._CPRManufacturingOrder_Custom.FE AS datvar3, dbo._CPRManufacturingOrder_Custom.TA, dbo._CPRManufacturingOrder_Custom.FFI,
dbo._CPRManufacturingOrder_Custom.FFD, dbo._CPRManufacturingOrder_Custom.LI, dbo._CPRManufacturingOrder_Custom.LD,
dbo._CPRManufacturingOrder_Custom.B
FROM dbo.FACOrderLineSL INNER JOIN
dbo.FACOrderSL ON dbo.FACOrderLineSL.IDOrder = dbo.FACOrderSL.IDOrder INNER JOIN
dbo.CPRManufacturingOrder ON dbo.FACOrderLineSL.IDManufacturingOrder = dbo.CPRManufacturingOrder.IDManufacturingOrder INNER JOIN
dbo._CPRManufacturingOrder_Custom ON dbo.FACOrderLineSL.IDManufacturingOrder = dbo._CPRManufacturingOrder_Custom.IDManufacturingOrder INNER JOIN
dbo.FACInvoicingTypeSL ON dbo.FACOrderSL.IDInvoicingType = dbo.FACInvoicingTypeSL.IDInvoicingType INNER JOIN
dbo._FACOrderSL_Custom ON dbo.FACOrderLineSL.IDOrder = dbo._FACOrderSL_Custom.IDOrder INNER JOIN
dbo._FACOrderLineSL_Custom ON dbo.FACOrderLineSL.IDOrderLine = dbo._FACOrderLineSL_Custom.IDOrderLine
WHERE (YEAR(dbo.CPRManufacturingOrder.PlannedEndDate) > 2007)
Pero con esta otra consulta, al añadir la tabla "_Decorados" y poniéndole un "Case" ya no me devuelve nada. He probado también sin el "Case" y simplemente diciendo que me muestre un dato de la tabla, pero nada. Si añado la tabla "_Decorados" ya no devuelve nada.
SELECT CASE WHEN _CPRManufacturingOrder_Custom.Mano = 1 THEN 'I' WHEN _CPRManufacturingOrder_Custom.Mano = 2 THEN 'D' ELSE '' END AS datvar1,
dbo.FACOrderLineSL.Quantity AS envact, dbo._CPRManufacturingOrder_Custom.Ancho AS datvar4, dbo._CPRManufacturingOrder_Custom.Alto AS datvar5,
dbo.FACOrderLineSL.CodCompany AS codemp, dbo.FACInvoicingTypeSL.CodInvoicingType AS tipcont, dbo.FACOrderSL.CodOrder AS numped,
dbo.FACOrderLineSL.IDOrderLine AS numlin, dbo.CPRManufacturingOrder.InternalCode AS numalb,
CASE WHEN _Decorados.CodDecorados = ' ' THEN _Decorados.Description ELSE '' END AS datvar2, dbo._CPRManufacturingOrder_Custom.Fondo AS datvar6,
YEAR(dbo.CPRManufacturingOrder.PlannedEndDate) AS AÑO, dbo._CPRManufacturingOrder_Custom.ZonaEnvio AS ENVIO,
dbo._CPRManufacturingOrder_Custom.FE AS datvar3, dbo._CPRManufacturingOrder_Custom.TA, dbo._CPRManufacturingOrder_Custom.FFI,
dbo._CPRManufacturingOrder_Custom.FFD, dbo._CPRManufacturingOrder_Custom.LI, dbo._CPRManufacturingOrder_Custom.LD,
dbo._CPRManufacturingOrder_Custom.B
FROM dbo.FACOrderLineSL INNER JOIN
dbo.FACOrderSL ON dbo.FACOrderLineSL.IDOrder = dbo.FACOrderSL.IDOrder LEFT OUTER JOIN
dbo.CPRManufacturingOrder ON dbo.FACOrderLineSL.IDManufacturingOrder = dbo.CPRManufacturingOrder.IDManufacturingOrder INNER JOIN
dbo._CPRManufacturingOrder_Custom ON dbo.FACOrderLineSL.IDManufacturingOrder = dbo._CPRManufacturingOrder_Custom.IDManufacturingOrder INNER JOIN
dbo.FACInvoicingTypeSL ON dbo.FACOrderSL.IDInvoicingType = dbo.FACInvoicingTypeSL.IDInvoicingType LEFT OUTER JOIN
dbo._FACOrderSL_Custom ON dbo.FACOrderLineSL.IDOrder = dbo._FACOrderSL_Custom.IDOrder LEFT OUTER JOIN
dbo._FACOrderLineSL_Custom ON dbo.FACOrderLineSL.IDOrderLine = dbo._FACOrderLineSL_Custom.IDOrderLine LEFT OUTER JOIN
dbo._Decorados ON dbo._FACOrderLineSL_Custom.IDDecorados = dbo._Decorados.IDDecorados
WHERE (YEAR(dbo.CPRManufacturingOrder.PlannedEndDate) > 2007)