salix/db/routines/vn/views/ticketMRW.sql

48 lines
1.3 KiB
SQL

CREATE OR REPLACE DEFINER=`root`@`localhost`
SQL SECURITY DEFINER
VIEW `vn`.`ticketMRW`
AS SELECT `ticket`.`agencyModeFk` AS `id_Agencia`,
`ticket`.`companyFk` AS `empresa_id`,
`Consignatarios`.`consignatario` AS `Consignatario`,
`Consignatarios`.`domicilio` AS `DOMICILIO`,
`Consignatarios`.`poblacion` AS `POBLACION`,
`Consignatarios`.`codPostal` AS `CODPOSTAL`,
`Consignatarios`.`telefono` AS `telefono`,
IFNULL(
IFNULL(
IFNULL(
IFNULL(`Consignatarios`.`movil`, `Clientes`.`movil`),
`Consignatarios`.`telefono`
),
`Clientes`.`telefono`
),
0
) AS `movil`,
`Clientes`.`if` AS `IF`,
`ticket`.`id` AS `Id_Ticket`,
`ticket`.`warehouseFk` AS `warehouse_id`,
`Consignatarios`.`id_consigna` AS `Id_Consigna`,
`Paises`.`Codigo` AS `CodigoPais`,
`ticket`.`shipped` AS `Fecha`,
`province`.`province_id` AS `province_id`,
`ticket`.`landed` AS `landing`
FROM (
(
(
(
`vn2008`.`Clientes`
JOIN `vn2008`.`Consignatarios` ON(
`Clientes`.`id_cliente` = `Consignatarios`.`Id_cliente`
)
)
JOIN `vn`.`ticket` ON(
`Consignatarios`.`id_consigna` = `ticket`.`addressFk`
)
)
JOIN `vn2008`.`province` ON(
`Consignatarios`.`province_id` = `province`.`province_id`
)
)
JOIN `vn2008`.`Paises` ON(`province`.`Paises_Id` = `Paises`.`Id`)
);