1
I have the following code:
(is from a table that the representatives have the same code, which generates duplicated values, I solve this by taking the most current representative, in short the last guy who synchronized)
select distinct top $numeroRepresentantes
t.nomerepresentante,
t.codigorepresentante
from (SELECT distinct
s.nomeRepresentante,
s.codigorepresentante,
datasinc
FROM vw_Sincronismo s
where s.CodigoRepresentante in(102,120)
ORDER BY s.datasinc desc) as t
Which returns me the following error:
Message 1033, Level 15, Status 1, Line 5
Invalid ORDER BY clause in displays, embedded functions, derived tables, common sub-consultations and table expressions, unless TOP, OFFSET or FOR XML is also specified.
Sorry the ignorance I don’t know much about SQL, but I need all the results of the table to appear, if necessary, I can’t use a TOP large to solve my problems, I would like to understand what happened here
About "the last guy who synchronized", requires the last synchronization of each representative OR the last synchronization, whatever the representative?
– José Diz
I use the latest timing to ensure that he is the "current owner" of codigoRepresentant assigned to him, other representatives with the same code, I assume as "dismissed"
– Leonardo da Silva
I understood about code reuse; I even changed code #1 to get only the last synchronization of each value of
CodigoRepresentante
. The question now is: what the query should return?– José Diz
@Josédiz, exactly that, the last representative with the x code, I was studying his code and had already made this change that you implemented in v2, so I just marked it as the correct answer
– Leonardo da Silva