Hi, i am facing some problems to run a sql statement. I am trying to use an external Id inside the subquery.

The query is ok, if I put a hard code id inside the subquery, it runs normally.

Thank you!


Can you show here the executed SQL? 


Hi Thiago,

I tried, but couldn't reproduce the exact error message in your scenario.

But the query you should probably use is this:

SELECT {Table1}.[Numero]
        , ''
        , {Table1}.[Id]
        , (SELECT {Table2}.[Id]
            FROM {Table2}
            WHERE {Table2}.[Table1Id] = {Table1}.[Id]
              AND {Table2}.[ModifiedOn] = (SELECT MAX({Table2}.[ModifiedOn]) FROM {Table2} WHERE {Table2}.[Table1Id] = {Table1}.[Id])
FROM {Table1}

It will get the last record in Table2 associated with Table1, but way more performatic than using order by.

Hope this helps.