2
I have a bank called completo
, whose table dados
is:
id cpf nome
1 38831370570 joao da silva
2 27283620508 maria joaquina
3 94470661945 carlos eduardo
I would like to 'Filter' all Cpfs q contain a certain digit in the ninth position, based on this:
"To determine in which Brazilian state a CPF was issued, it is necessary to obtain the last digit of the CPF by ignoring the two check digits / verifiers. An example of how to determine this number is CPF no XXX.XX.X6-XX. Highlighted we see the last valid number of the CPF, ignoring the check digits."
I want to search in the bank all Cpfs from Rio de Janeiro, for example, according to this relationship:
1. Distrito Federal, Goiás, Mato Grosso do Sul e Tocantins;
2. Pará, Amazonas, Acre, Amapá, Rondônia e Roraima;
3. Ceará, Maranhão e Piauí;
4. Pernambuco, Rio Grande do Norte, Paraíba e Alagoas;
5. Bahia e Sergipe;
6. Minas Gerais;
7. Rio de Janeiro e Espírito Santo;
8. São Paulo;
9. Paraná e Santa Catarina;
10.Rio Grande do Sul.
Grateful Friend Helped Me
– Ismael Alfredo
@Leocaracciolo which error is returning ?
– Leonardo Bonetti
@Leocaracciolo that bizarre, Oo now I’m confused, will the guy positively me wrong?
– Leonardo Bonetti
And @Leocaracciolo his answer is incorrect, he wants the 9°; digito being the number of the state, his is pulling the last one, the 11°. I’ll open it in the bank here.
– Leonardo Bonetti
@Leocaracciolo Yours is not returning anything because there is no digit '8' in the ninth position in any of the records in your table :)
– Leonardo Bonetti
@Leocaracciolo Because it has number '8' in the 11° position, but the correct is to have in the ninth, yours is right, just by "SELECT * FROM data WHERE SUBSTRING(Cpf,9) = '8'"
– Leonardo Bonetti
It is , ai depends on the digit you put, if you put "SELECT * FROM WHERE SUBSTRING data(Cpf,9) = '5'" in your database will return results pq there is '5' in the ninth position.
– Leonardo Bonetti
@Leocaracciolo You’re right, I’ll edit my answer.
– Leonardo Bonetti
I was confusing it with the Javascript substring too... but thanks for the fix.
– Leonardo Bonetti
The answer is now correct, it is always suggested to complement with a SQL Fiddle to value the response with a demonstration.
– Bacco