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 `Tickets`.`Id_Agencia` AS `id_Agencia`,
`Tickets`.`empresa_id` 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`,
`Tickets`.`Id_Ticket` AS `Id_Ticket`,
`Tickets`.`warehouse_id` AS `warehouse_id`,
`Consignatarios`.`id_consigna` AS `Id_Consigna`,
`Paises`.`Codigo` AS `CodigoPais`,
`Tickets`.`Fecha` AS `Fecha`,
`province`.`province_id` AS `province_id`,
`Tickets`.`landing` AS `landing`
FROM (
(
(
(
`vn2008`.`Clientes`
JOIN `vn2008`.`Consignatarios` ON(
`Clientes`.`id_cliente` = `Consignatarios`.`Id_cliente`
)
)
JOIN `vn2008`.`Tickets` ON(
`Consignatarios`.`id_consigna` = `Tickets`.`Id_Consigna`
)
)
JOIN `vn2008`.`province` ON(
`Consignatarios`.`province_id` = `province`.`province_id`
)
)
JOIN `vn2008`.`Paises` ON(`province`.`Paises_Id` = `Paises`.`Id`)
)