Galera, minha query estaria assim, e ao chegar no Inner Join dá o seguinte erro: "variable does not exist ‘SC7’" e o código da query é:
cQryReport += "FROM" + RetSqlTab(SC7)+"SC7"+ CRLF
cQryReport += RetSqlTab(SCR) + "SCR. ON SC7.C7_NUM = CR_NUM AND SC7.D_E_L_E_T_ <> '*' AND SCR.D_E_L_E_T_ <> '*' " + CRLF
cQryReport += RetSqlTab(SA2) +" A2 ON A2_COD = SC7.C7_FORNECE AND A2.D_E_L_E_T_ <> '*' " + CRLF
cQryReport += RetSqlTab(SYS_USR) + "USR ON USR_ID = CR_USER AND USR.D_E_L_E_T_ <> '*' " + CRLF
cQryReport += RetSqlTab(SF1) +"F1 on F1_FORNECE = SC7.C7_FORNECE and F1_LOJA = C7_LOJA AND F1.D_E_L_E_T_ <> '*' " + CRLF
como também testei essa possibilidade:
cQryReport += "FROM" + RetSQLName(SC7) + " C7 " + CRLF
cQryReport += " INNER JOIN " + RetSQLName(SCR) + "CR ON C7.C7_NUM = CR_NUM AND C7.D_E_L_E_T_ <> '*' AND CR.D_E_L_E_T_ <> '*' " + CRLF
cQryReport += " INNER JOIN" + RetSQLName(SA2) +" A2 ON A2_COD = C7.C7_FORNECE AND A2.D_E_L_E_T_ <> '*' " + CRLF
cQryReport += " INNER JOIN" + RetSQLName(SYS_USR) + "USR ON USR_ID = CR_USER AND USR.D_E_L_E_T_ <> '*' " + CRLF
cQryReport += " INNER JOIN "+ RetSQLName(SF1) +"F1 on F1_FORNECE = C7.C7_FORNECE and F1_LOJA = C7_LOJA AND F1.D_E_L_E_T_ <> '*' " + CRLF
QUERY COMPLETA:
cQryReport += "SELECT SC7.C7_EMISSAO AS DATA_DISPONIBILIZADA, " + CRLF
cQryReport += " SCR.CR_DATALIB AS DATA_RECEBIMENTO, " + CRLF
cQryReport += " SA2.A2_NOME AS RAZAO_SOCIAL, " + CRLF
cQryReport += " SC7.C7_FORNECE AS COD_FORNECEDOR, " + CRLF
cQryReport += " SF1.F1_DOC AS NOTA, " + CRLF
cQryReport += " SCR.CR_TOTAL AS VALOR, " + CRLF
cQryReport += " SC7.C7_TOTAL, " + CRLF
cQryReport += " SCR.CR_NUM AS NUM_PEDIDO, " + CRLF
cQryReport += " USR.USR_NOME AS APROVADOR, " + CRLF
cQryReport += " SCR.CR_NIVEL, " + CRLF
cQryReport += " SCR.CR_STATUS Status_aprov, " + CRLF
cQryReport += " Case " + CRLF
cQryReport += " when SCR.CR_STATUS = 1 THEN 'Aguardando nível anterior' " + CRLF
cQryReport += " when SCR.CR_STATUS = 2 THEN 'Pendente' " + CRLF
cQryReport += " when SCR.CR_STATUS = 3 THEN 'Liberado' " + CRLF
cQryReport += " when SCR.CR_STATUS = 4 THEN 'Bloqueado' " + CRLF
cQryReport += " when SCR.CR_STATUS = 5 Then 'Liberado por outro aprovador' " + CRLF
cQryReport += " when SCR.CR_STATUS = 6 Then 'Rejeitado' " + CRLF
cQryReport += " when SCR.CR_STATUS = 7 then 'Rejeitado/Bloqueado por outro aprovador' " + CRLF
cQryReport += " else 'SEM STATUS' " + CRLF
cQryReport += "FROM" + RetSqlTab(SC7)+"SC7"+ CRLF
cQryReport += RetSqlTab(SCR) + "SCR. ON SC7.C7_NUM = CR_NUM AND SC7.D_E_L_E_T_ <> '*' AND SCR.D_E_L_E_T_ <> '*' " + CRLF
cQryReport += RetSqlTab(SA2) +" SA2 ON A2_COD = SC7.C7_FORNECE AND SA2.D_E_L_E_T_ <> '*' " + CRLF
cQryReport += RetSqlTab(SYS_USR) + "USR ON USR.USR_ID = SCR.CR_USER AND USR.D_E_L_E_T_ <> '*' " + CRLF
cQryReport += RetSqlTab(SF1) +"SF1 ON SF1.F1_FORNECE = SC7.C7_FORNECE AND SF1.F1_LOJA = SC7.C7_LOJA AND SF1.D_E_L_E_T_ <> '*' " + CRLF
cQryReport += "WHERE SC7.C7_CONAPRO IN ('B', 'L')" + CRLF
cQryReport += "AND SC7.C7_EMISSAO >= '" +DtoS(dDataDe) + "' AND SC7.C7_EMISSAO <='"+ DtoS(dDataAt)+"'"+ CRLF
cQryReport += "ORDER BY SF1.F1_DOC DESC, SCR.CR_NIVEL ASC" + CRLF