SELECT SC6.C6CLI CLIENTE,SC6.C6_PRODUTO PRODUTO,SC6.C6_NUM PEDIDO,SC6.C6_ITEM ITEM,SC6.C6_QTDVEN QTDTOTAL,SC6.C6_QTDENT QTDENTR,SC6.C6_UM UM,SC6.C6_PRCVEN PRECOUN,SC6.C6_ENTREG ENTREGA, SC6.C6_DVDTCLI ENTCLI,SC6.C6_TES TES,SC6.C6_BLQ BLOQUEIO,SC6.C6_NOTA NOTA,SC6.C6_SERIE SERIE,SC5.C5_EMISSAO EMISSAO,SC5.C5_CONDPAG CONDPAG,SC6.C6_LOCAL LOCPRO,SC6.C6_PEDCLI PEDCLI FROM SC6010 SC6 (NOLOCK INDEX=SC60101 ) , SC5010 SC5 (NOLOCK INDEX=SC50101 ) WHERE SC6.C6_FILIAL = '01' AND SC6.C6_CLI >= ' ' AND SC6.C6_CLI <= 'ZZZZZZ' AND SC6.C6_ENTREG >= '20230101' AND SC6.C6_ENTREG <= '20231231' AND SC6.C6_PRODUTO >= ' ' AND SC6.C6_PRODUTO <= 'ZZZZZZZZZZZZ ' AND (SC6.C6_QTDENT < SC6.C6_QTDVEN OR (SC6.C6_QTDVEN = 0 AND SC6.C6_NOTA = SPACE(6))) AND SC5.C5_NUM = SC6.C6_NUM AND SC5.C5_FILIAL=SC6.C6_FILIAL AND SC5.C5_EMISSAO >= '20230101' AND SC5.C5_EMISSAO <= '20231231' AND SC6.C6_BLQ <> 'R' AND SC5.D_E_L_E_T <> '' AND SC6.DE_L_E_T <> '' AND SC5.C5_TIPO NOT IN ('B','D') AND (SC6.C6_LOCAL BETWEEN ' ' AND 'ZZ') AND SC6.C6_PEDCLI NOT LIKE '%SEM%'