posStart = 0 count = select O.*, case when (O.DataSpedFattura = '0000-00-00') then '2002-01-01' else O.DataSpedFattura end as DataSpedizioneFattura, DAYOFYEAR(O.DataSpedFattura), DAYOFYEAR(NOW()) - DAYOFYEAR(O.DataSpedFattura) as DiffGiorni, A.idagenti as IdAgenti, A.nome as NomeAgente, F.idfornitori as IdFornitori, F.Nome as NomeFornitore, C.idclienti as IdClienti, C.nome as NomeCliente, P.idpagamenti as IdPagamenti, P.modalita as TipoPagamento from ordini_2007 O inner join pagamenti_2007 P on P.IdPagamenti = O.idpagamento inner join fornitori_2007 F on F.idfornitori = O.idfornitore inner join clienti_2007 C on C.idclienti = O.idcliente inner join agenti_2007 A on A.idagenti = O.idagente where O.saldofattura = 0 and O.NumFattura <> 0 and O.dataspedfattura <= NOW() and O.idfornitore = F.idfornitori and O.idcliente = C.idclienti order by C.nome, O.dataspedfattura