cQuery := "SELECT "cCampoSQL", SUM(SE2.E2_SALDO) AS SALDO " cQuery = "FROM "+RetSqlName("VV1")" VV1 " cQuery = "JOIN "+RetSqlName("VV2")" VV2 ON ( VV2.VV2_FILIAL='"cVV2Fil"' AND VV1.VV1_CODMAR=VV2.VV2_CODMAR AND VV1.VV1_MODVEI=VV2.VV2_MODVEI AND VV2.D_E_L_E_T_=' ' ) " cQuery = "LEFT JOIN "+RetSqlName("VVC")" VVC ON ( VVC.VVC_FILIAL='"cVVCFil"' AND VVC.VVC_CODMAR=VV1.VV1_CODMAR AND VVC.VVC_CORVEI=VV1.VV1_CORVEI AND VVC.D_E_L_E_T_=' ' ) " cQuery = "LEFT JOIN "+RetSqlName("SB1")" SB1 ON ( SB1.B1_FILIAL='"cSB1Fil"' AND SB1.B1_GRUPO='"cGruVei"' AND SB1.B1_CODITE=VV1.VV1_CHAINT AND SB1.D_E_L_E_T_=' ' ) " cQuery = "LEFT JOIN "+RetSqlName("VVF")" VVF ON ( VVF.VVF_FILIAL=VV1.VV1_FILENT AND VVF.VVF_TRACPA=VV1.VV1_TRACPA AND VVF.D_E_L_E_T_=' ' ) " cQuery = "LEFT JOIN "+RetSqlName("SF1")" SF1 ON ( SF1.F1_FILIAL=VVF.VVF_FILIAL AND SF1.F1_DOC=VVF.VVF_NUMNFI AND SF1.F1_SERIE=VVF.VVF_SERNFI AND SF1.F1_FORNECE=VVF.VVF_CODFOR AND SF1.F1_LOJA=VVF.VVF_LOJA AND SF1.D_E_L_E_T_=' ' ) " cQuery = "LEFT JOIN "+RetSqlName("SE2")" SE2 ON ( SE2.E2_FILIAL IN ("cSE2Fil") AND SE2.E2_NUM=SF1.F1_DOC AND SE2.E2_PREFIXO=SF1.F1_PREFIXO AND SE2.E2_FORNECE=SF1.F1_FORNECE AND SE2.E2_LOJA=SF1.F1_LOJA AND SE2.D_E_L_E_T_=' ' AND SE2.E2_TIPO NOT IN "cNTpTit" ) " cQuery = "WHERE VV1.VV1_FILIAL='"+cVV1Fil"' AND VV1.VV1_SITVEI IN ('0','2','3','4','8') AND VV1.VV1_CODMAR='"aAuxni,1"' AND " If !Empty(aAuxni,2) cQuery = "VV1.VV1_MODVEI IN ("+aAuxni,2") AND " Else Loop // Pula linha do vetor quando nao existe MODELO de Veiculo para a Marca EndIf cQuery = "VV1.VV1_ESTVEI='"+left(cEstVei,1)"' AND " If !Empty(VAI->VAI_TIPVEI) .and. VAI->VAI_TIPVEI <> "0" // Tipo do Veiculo (Normal/Taxi/Frotista) cQuery = "VV1.VV1_TIPVEI='"+VAI->VAI_TIPVEI"' AND " EndIf If !Empty(cTipCor) cQuery = "VVC.VVC_TIPCOR='"+left(cTipCor,1)"' AND " EndIf If !Empty(aAuxni,3) cQuery = "VV1.VV1_CORVEI IN ("+aAuxni,3") AND " Else Loop // Pula linha do vetor quando nao existe COR de Veiculo para a Marca EndIf cQuery = "VV1.VV1_FILENT='"+cVVFFil"' AND " cQuery += "VV1.D_E_L_E_T_=' ' " If lVXC01QRY cVXC01QRY := ExecBlock("VXC01QRY",.f.,.f.) If !Empty(cVXC01QRY) cQuery = " AND "+cVXC01QRY" " EndIf EndIf cQuery = "GROUP BY "+cCampoSQL" " cQuery += "ORDER BY VV1.VV1_CHAINT " dbUseArea( .T., "TOPCONN", TcGenQry( ,, cQuery ), cQAlSQL , .F., .T. ) |