on 02-23-2021 2:23 AM
Hello
I'm having a problem, trying to do a SQL Script, Table Function in DataWareHouse Cloud
1 . I have a query that returns 2 records as seen in the image belo
Now what I want is to go through this query record by record, I am doing it using a For loop, as seen in the image
What I want to obtain is that for each iteration, a query is made to a table using as a condition the id of the records of the first column, but in the end I only get one record, regardless of whether I add the return output inside or outside the loop.
Try to do the same but using a cursor and I get the same result.
I am trying to make the end with this code. is to iterate to bring you a top 1 of each repeated code.
I appreciate any collaboration.
Hi Karen,
there is no need for a LOOP. You are thinking too complicated. Try an INNER JOIN instead. This should look like this:
DO BEGIN
lt_codigo =
SELECT cod_cliente as codigo
FROM rt_tt_clientestmp
WHERE status = 'Activo'
GROUP BY cod_cliente
HAVING COUNT(*) > 1;
SELECT cod_cliente,
cod_canal,
txt_canal,
cod_subcanal,
fila
FROM rt_tt_clientestmp AS t1
INNER JOIN :lt_codigo AS t2
ON t1.cod_cliente = t2.codigo;
END;
With best regards,
Jörg
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
User | Count |
---|---|
86 | |
10 | |
10 | |
9 | |
7 | |
7 | |
6 | |
5 | |
4 | |
4 |
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.