Get distinct column values into varchar value

85 Views Asked by At

I have a large query, and in it a subquery in which I try to get all distinct rows from a temporary table column

(SELECT
        STUFF((
        SELECT DISTINCT #SomeTemporaryTable.CountryName
        FROM #SomeTemporaryTable
        WHERE (#SomeTemporaryTable.SomeId = 1
        AND #SomeTemporaryTable.AnotherId = 2)
        FOR XML PATH(''''),TYPE).value(''(./text())[1]'',''VARCHAR(MAX)'')
    ,1,2,'''') AS BreakDownLocationCountry,

The problem is that I am receiving the following error:

The ORDER BY clause is invalid in views, inline functions, derived tables, subqueries, and common table expressions, unless TOP or FOR XML is also specified.

Can someone please help me?

P.S : Microsft SQL 2008

0

There are 0 best solutions below