I’ll put here how I solved this problem, maybe it helps someone in the future.
Remembering that what I did here is not recommended but it was the way I managed to solve this problem until the integration of a new CRM.
The main problems were uniting all 15 speakers of phones and removing the blanks.
Follows solution...
#1 - I loaded all received base with 32 columns(pure file).
#2 - Here the treatment begins, I do not need to use all the columns of the loaded file so using the idea of Motta, I created a View and repeated the query until the column TELEFONE_15, as below.
CREATE VIEW OR REPLACE VIEW VIEW_CLIENTE AS
SELECT TRIM(OPERACAO) AS OPERACAO,
TRIM(NOME) AS NOME,
TRIM(CPF) AS CPF,
RTRIM(TELEFONE) AS TELEFONE,
RTRIM(substring(SAL_AB_ATR_CL_AG,19,9)) as ATR
FROM TABELA
WHERE RTRIM(TELEFONE) IS NOT NULL
UNION ALL
SELECT TRIM(OPERACAO) AS OPERACAO,
TRIM(NOME) AS NOME,
TRIM(CPF) AS CPF,
RTRIM(TELEFONE_2) AS TELEFONE,
RTRIM(substring(SAL_AB_ATR_CL_AG,19,9)) as ATR
FROM TABELA
WHERE RTRIM(TELEFONE_2) IS NOT NULL
#3 -After VIEW was created I run a CASE to know what is Fixed or Mobile, so people who will use the base in the future can have a better view than prioritize...
SELECT operacao, nome, cpf, telefone,
CASE
WHEN LENGTH(tel1) = 10 THEN 'Fixo'
WHEN LENGTH(tel1) = 11 THEN 'Celular'
ELSE 'erro' END
FROM VIEW_CLIENTE LIMIT 10;
#4 - After that export the result and import in the production bank is end of the problem.
Again, remembering that this solution I made I believe is not recommended but as I receive the client base so I have to find my way to work...
Thank you!
"has 15 telephone speakers" What is this modeling? should have a single column and insert on demand if you need 1 inserts 1, if you need 5 inserts 5 and so on. You are trying to solve a modeling problem in the query, which is very bad. About the query, no matter if you are going to do Join or Union or other trick, you will have to do 15 times, the best would be to filter this, put in a table the part with the data you need and list this, as should be this modeling, but for that you would need to use a Procedure
– Ricardo Pontual
Obg by the return Ricardo, I agree with you about this modeling but unfortunately this is how I get from the customer and how they do not want to change need to do the treatment on my side for use.
– Mr Poke
explain one thing better, imagine that the line has the phones 1 to 3 filled and the rest null, which one will return between them? the first? I don’t quite understand that
– Ricardo Pontual
That would be kind of irrelevant. If I only have these three phones would try to contact the three until I have positive feedback from any of them indicating that this X number is the current contact number of the customer.
– Mr Poke