1
In this select I am bringing all employees who accessed the application yesterday PO.DAT_COLETA
and who held blindfold yesterday PE.COD_PEDIDO
. But I also want to bring those who accessed yesterday and did not make sales, today I do it by PROCV in excel, it is possible to do it by query ?
SELECT
FUV.COD_UNIDADE_VENDA
,UV.NOM_UNIDADE_VENDA
,FUV.COD_FUNCIONARIO
,FU.NOM_FUNCIONARIO
,PO.DAT_COLETA
,PE.COD_PEDIDO
FROM FUNCIONARIO_UNIDADE_VENDA FUV
JOIN POSICAO_FUNCIONARIO PO ON FUV.COD_FUNCIONARIO = PO.COD_FUNCIONARIO
JOIN UNIDADE_VENDA UV ON FUV.COD_UNIDADE_VENDA = UV.COD_UNIDADE_VENDA
JOIN FUNCIONARIO FU ON FUV.COD_FUNCIONARIO = FU.COD_FUNCIONARIO
JOIN PEDIDO PE ON FUV.COD_FUNCIONARIO = PE.COD_FUNCIONARIO
WHERE
PO.DAT_COLETA >= CONVERT(CHAR(10), GETDATE()-1, 101) and PO.DAT_COLETA < CONVERT(CHAR(10), GETDATE(), 101)
AND PE.DAT_ENTREGA >= CONVERT(CHAR(10), GETDATE()-1, 101) and PE.DAT_ENTREGA < CONVERT(CHAR(10), GETDATE(), 101)
ORDER BY FUV.COD_UNIDADE_VENDA
A doubt, because you convert your date to char and then compare with another date?
– Jeferson Almeida
I’m just testing, then this will be taken out. In fact this query will have to be rotated 23:59, to bring all the people who accessed and made or did not make sales on the day. It is a retroactive report, do you understand? Because if the person access dat_collecting today is superimposed on the bank and stick the report.
– Lucas Eduardo da Silva
@Lucaseduardodasilva (1) If the employee accesses the application several times on the same day, in the POSICAO_FUNCIONARIO table is there a line for each access on the day or only one and only line on the day? // (2) Each day the employee registers a single global sales order or can register multiple sales orders for the same day?
– José Diz
@Lucaseduardodasilva (1) How are declared the columns DAT_COLETA and DAT_ENTREGA? (date, datetime, string etc). // (2) If string, what format? (dd/mm/yyyy, mm/dd/yyyy etc)
– José Diz
@José Diz Sim, are declared as datetime, and each new collection that the device sends to the bank overlaps the last, that is, there is only one line with the most recent dat_collection ever, so this script will be scheduled to run always 23:59, hugs.
– Lucas Eduardo da Silva