diegobueno Posted January 16, 2014 Topic Count: 12 Topics Per Day: 0.00 Content Count: 39 Content Per Day: 0.01 Reputation: 2 Achievement Points: 327 Solved Content: 0 Days Won: 1 Status: Offline Report Posted January 16, 2014 Pessoal, nao sei se vai ser de utilidade, mas coloco aqui uma consulta que pega, pelo numero do movimento (TMOV.NUMEROMOV) todos os itens dele e valida o codigo EAN, espero que ajude, caso a NFe seja rejeitada por codigo EAN invalido. SELECT --TITMMOV.IDMOV, --TMOV.NUMEROMOV, --TMOV.DATAEMISSAO, --TITMMOV.IDPRD, TPRODUTO.CODIGOPRD, TPRODUTO.NOMEFANTASIA, TPRDCODIGO.CODIGO, --VALIDAÇÃO DO CÓDIGO DE BARRAS DIGITO_CADASTRADO=RIGHT(TPRDCODIGO.CODIGO,1), DIGITO_CERTO= 10-(RIGHT(CAST(SUBSTRING(TPRDCODIGO.CODIGO,1,1) AS INT)+(CAST(SUBSTRING(TPRDCODIGO.CODIGO,2,1) AS INT)*3)+CAST(SUBSTRING(TPRDCODIGO.CODIGO,3,1) AS INT)+(CAST(SUBSTRING(TPRDCODIGO.CODIGO,4,1) AS INT)*3)+CAST(SUBSTRING(TPRDCODIGO.CODIGO,5,1) AS INT)+(CAST(SUBSTRING(TPRDCODIGO.CODIGO,6,1) AS INT)*3)+CAST(SUBSTRING(TPRDCODIGO.CODIGO,7,1) AS INT)+(CAST(SUBSTRING(TPRDCODIGO.CODIGO,8,1) AS INT)*3)+CAST(SUBSTRING(TPRDCODIGO.CODIGO,9,1) AS INT)+(CAST(SUBSTRING(TPRDCODIGO.CODIGO,10,1) AS INT)*3)+CAST(SUBSTRING(TPRDCODIGO.CODIGO,11,1) AS INT)+(CAST(SUBSTRING(TPRDCODIGO.CODIGO,12,1) AS INT)*3),1)), CASE WHEN RIGHT(TPRDCODIGO.CODIGO,1) <> (10-(RIGHT(CAST(SUBSTRING(TPRDCODIGO.CODIGO,1,1) AS INT)+(CAST(SUBSTRING(TPRDCODIGO.CODIGO,2,1) AS INT)*3)+CAST(SUBSTRING(TPRDCODIGO.CODIGO,3,1) AS INT)+(CAST(SUBSTRING(TPRDCODIGO.CODIGO,4,1) AS INT)*3)+CAST(SUBSTRING(TPRDCODIGO.CODIGO,5,1) AS INT)+(CAST(SUBSTRING(TPRDCODIGO.CODIGO,6,1) AS INT)*3)+CAST(SUBSTRING(TPRDCODIGO.CODIGO,7,1) AS INT)+(CAST(SUBSTRING(TPRDCODIGO.CODIGO,8,1) AS INT)*3)+CAST(SUBSTRING(TPRDCODIGO.CODIGO,9,1) AS INT)+(CAST(SUBSTRING(TPRDCODIGO.CODIGO,10,1) AS INT)*3)+CAST(SUBSTRING(TPRDCODIGO.CODIGO,11,1) AS INT)+(CAST(SUBSTRING(TPRDCODIGO.CODIGO,12,1) AS INT)*3),1))) THEN 'ERRADO' END SELECT --TITMMOV.IDMOV, --TMOV.NUMEROMOV, --TMOV.DATAEMISSAO, --TITMMOV.IDPRD, TPRODUTO.CODIGOPRD, TPRODUTO.NOMEFANTASIA, TPRDCODIGO.CODIGO, --VALIDAÇÃO DO CÓDIGO DE BARRAS DIGITO_CADASTRADO=RIGHT(TPRDCODIGO.CODIGO,1), DIGITO_CERTO= 10-(RIGHT(CAST(SUBSTRING(TPRDCODIGO.CODIGO,1,1) AS INT)+(CAST(SUBSTRING(TPRDCODIGO.CODIGO,2,1) AS INT)*3)+CAST(SUBSTRING(TPRDCODIGO.CODIGO,3,1) AS INT)+(CAST(SUBSTRING(TPRDCODIGO.CODIGO,4,1) AS INT)*3)+CAST(SUBSTRING(TPRDCODIGO.CODIGO,5,1) AS INT)+(CAST(SUBSTRING(TPRDCODIGO.CODIGO,6,1) AS INT)*3)+CAST(SUBSTRING(TPRDCODIGO.CODIGO,7,1) AS INT)+(CAST(SUBSTRING(TPRDCODIGO.CODIGO,8,1) AS INT)*3)+CAST(SUBSTRING(TPRDCODIGO.CODIGO,9,1) AS INT)+(CAST(SUBSTRING(TPRDCODIGO.CODIGO,10,1) AS INT)*3)+CAST(SUBSTRING(TPRDCODIGO.CODIGO,11,1) AS INT)+(CAST(SUBSTRING(TPRDCODIGO.CODIGO,12,1) AS INT)*3),1)), CASE WHEN RIGHT(TPRDCODIGO.CODIGO,1) <> (10-(RIGHT(CAST(SUBSTRING(TPRDCODIGO.CODIGO,1,1) AS INT)+(CAST(SUBSTRING(TPRDCODIGO.CODIGO,2,1) AS INT)*3)+CAST(SUBSTRING(TPRDCODIGO.CODIGO,3,1) AS INT)+(CAST(SUBSTRING(TPRDCODIGO.CODIGO,4,1) AS INT)*3)+CAST(SUBSTRING(TPRDCODIGO.CODIGO,5,1) AS INT)+(CAST(SUBSTRING(TPRDCODIGO.CODIGO,6,1) AS INT)*3)+CAST(SUBSTRING(TPRDCODIGO.CODIGO,7,1) AS INT)+(CAST(SUBSTRING(TPRDCODIGO.CODIGO,8,1) AS INT)*3)+CAST(SUBSTRING(TPRDCODIGO.CODIGO,9,1) AS INT)+(CAST(SUBSTRING(TPRDCODIGO.CODIGO,10,1) AS INT)*3)+CAST(SUBSTRING(TPRDCODIGO.CODIGO,11,1) AS INT)+(CAST(SUBSTRING(TPRDCODIGO.CODIGO,12,1) AS INT)*3),1))) THEN 'ERRADO' END FROM TMOV INNER JOIN TITMMOV ON TITMMOV.IDMOV = TMOV.IDMOV INNER JOIN TPRODUTO ON TPRODUTO.IDPRD = TITMMOV.IDPRD LEFT JOIN TPRDCODIGO ON TPRDCODIGO.IDPRD = TPRODUTO.IDPRD WHERE TMOV.NUMEROMOV='000096906' FROM TMOV INNER JOIN TITMMOV ON TITMMOV.IDMOV = TMOV.IDMOV INNER JOIN TPRODUTO ON TPRODUTO.IDPRD = TITMMOV.IDPRD LEFT JOIN TPRDCODIGO ON TPRDCODIGO.IDPRD = TPRODUTO.IDPRD WHERE TMOV.NUMEROMOV='000096906' Quote
yuri.menon Posted January 16, 2014 Topic Count: 29 Topics Per Day: 0.01 Content Count: 133 Content Per Day: 0.03 Reputation: 5 Achievement Points: 979 Solved Content: 0 Days Won: 3 Status: Offline Age: 34 Report Posted January 16, 2014 Isso aí cara! Mais coisa pra ficar indexada no Google. Valeu! O ForumRM é eterno... esse seu conteúdo sempre estará aqui e no Google Quote
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.