Valdir Posted June 10, 2018 Report Share Posted June 10, 2018 Boas... Pessoal, preciso fazer uma pesquisa na Tabela CEST onde será retornado o valor do último resultado, mesmo que parcial, encontrado. Exemplo: - O Cliente digita o NCM "84842000" - Na Tabela do CEST 2018 não existe esse NCM completo, porém existe o Grupo, no qual ele pertence. Neste caso seria "8484". Como faço uma pesquisa para encontrar todas as variáveis do NCM na Tabela CEST. ? Obrigado. Quote Link to comment Share on other sites More sharing options...
kleyber Posted June 11, 2018 Report Share Posted June 11, 2018 Left(NCM,4) Valdir 1 Quote Link to comment Share on other sites More sharing options...
kapiaba Posted June 11, 2018 Report Share Posted June 11, 2018 OrdWildSeek() Valdir 1 Quote Link to comment Share on other sites More sharing options...
miragerr Posted June 11, 2018 Report Share Posted June 11, 2018 Ola, Bom dia amigos Eu faço da seguinte forma: Private cCEST_SQL := Space(7) Private cNome_Natureza := Space(180) aCEST := Array_SQL("Select codigo_cest, descri_cest FROM cest WHERE ncm_cest = ?",,{ VMNCMPRO_ESTO } ) IF Len( aCest ) == 1 .AND. !lVerifica_Cest MsgInfo("Encontrado somente uma ocorrencia para este NCM","Atenção...") cNome_CEST := aCEST[ 1, 2 ] VMCEST_NCM_ESTO := aCEST[ 1, 1 ] Retu Endif aCEST := Array_SQL("Select codigo_cest, descri_cest, ncm_cest FROM cest WHERE MID( ncm_cest, 1, 6 ) = '"+Substr(VMNCMPRO_ESTO,1,6)+"'" ) IF Empty( aCEST ) aCEST := Array_SQL("Select codigo_cest, descri_cest, ncm_cest FROM cest WHERE MID( ncm_cest, 1, 4 ) = '"+Substr(VMNCMPRO_ESTO,1,4)+"'" ) IF Empty( aCEST ) MsgInfo( "Não foi encontrado nenhuma ocorrencia para este NCM"+CRLF+"Provavelmente este NCM não seja Substituição Tributária","Atenção..." ) cNome_CEST := '' VMCEST_NCM_ESTO := Space(7) Retu EndIF Endif Valdir 1 Quote Link to comment Share on other sites More sharing options...
Valdir Posted June 11, 2018 Author Report Share Posted June 11, 2018 Amigos... Obrigado pelas respostas. Jackson... seria mais ou menos por ai. Teria um exemplo em DBF ? Abrs. Quote Link to comment Share on other sites More sharing options...
Jorge Andrade Posted June 11, 2018 Report Share Posted June 11, 2018 Amigos... Obrigado pelas respostas. Jackson... seria mais ou menos por ai. Teria um exemplo em DBF ? Abrs. Valdir Esses dias respondemos algo parecido, onde vc deve fazer um pesquisa inicialmente pelo código inteiro com bytes, se não achar, procure por 6 bytes, não achando, continue até esgotar todas as possibilidade. mais ou menos isso , a grosso modo: SEEK wcodncm //INTEIRO IF FOUND() wdescricao := descricao wcest := cest ELSE SEEK SUBSTR(wcodncm,1,6) + SPACE(2) //6 BYTES, DEVE MOSTRAR TODOS OS POSSIVEIS PARA ESCOLHA IF FOUND() wcest := cest wdescricao := descricao ELSE SEEK SUBSTR(wcodncm,1,4) + SPACE(4) //4 BYTES , DEVE MOSTRAR TODOS OS POSSIVEIS PARA ESCOLHA IF FOUND() wcest := cest wdescricao := descricao ELSE SEEK SUBSTR(wcodncm,1,2) + SPACE(6) //2 BYTES QUE É O GENERO, , DEVE MOSTRAR TODOS OS POSSIVEIS PARA ESCOLHA IF FOUND() wcest := cest wdescricao := descricao ENDIF ENDIF ENDIF ENDIF []s, Valdir 1 Quote Link to comment Share on other sites More sharing options...
Wellington Vieira Posted June 11, 2018 Report Share Posted June 11, 2018 Boa tarde, Eu tive a mesma dúvida, e as respostas me ajudaram. Caso queira dar uma olhada. http://fivewin.com.br/index.php?/topic/27528-relacionar-a-tabela-cest-com-a-tabela-ncm/#comment-282455 Valdir 1 Quote Link to comment Share on other sites More sharing options...
Valdir Posted June 12, 2018 Author Report Share Posted June 12, 2018 Valdir Esses dias respondemos algo parecido, onde vc deve fazer um pesquisa inicialmente pelo código inteiro com bytes, se não achar, procure por 6 bytes, não achando, continue até esgotar todas as possibilidade. mais ou menos isso , a grosso modo: SEEK wcodncm //INTEIRO IF FOUND() wdescricao := descricao wcest := cest ELSE SEEK SUBSTR(wcodncm,1,6) + SPACE(2) //6 BYTES, DEVE MOSTRAR TODOS OS POSSIVEIS PARA ESCOLHA IF FOUND() wcest := cest wdescricao := descricao ELSE SEEK SUBSTR(wcodncm,1,4) + SPACE(4) //4 BYTES , DEVE MOSTRAR TODOS OS POSSIVEIS PARA ESCOLHA IF FOUND() wcest := cest wdescricao := descricao ELSE SEEK SUBSTR(wcodncm,1,2) + SPACE(6) //2 BYTES QUE É O GENERO, , DEVE MOSTRAR TODOS OS POSSIVEIS PARA ESCOLHA IF FOUND() wcest := cest wdescricao := descricao ENDIF ENDIF ENDIF ENDIF []s, Obrigado amigo Jorge... É isso mesmo que estava precisando. Valeu. Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.