I have a problem with SQL Server 2005 (Express Edition) with a UNION query.
I have this table Orders with the following columns: OrdNr, Prio Now I want to order by orders in two ways, the first way is urgent orders (so prio is 6 or 16), and the second way, the rest of the orders are sorted by Prio.
So this is what my table looks like:
ORDNR PRIO 1 6 2 16 3 2 4 8
I want it:
ORDNR PRIO 2 16 1 6 4 8 3 2
My query attempt was as follows:
SELECT OrdNbr, Prio FROM Orders WHERE Prio IN (6,16) ORDER BY Prio DESC UNION SELECT OrdNbr, Prio FROM Orders WHERE Prio NOT IN (6,16) ORDER BY Prio DESC
But I get an SQL error message: Syntax error next to UNION
Please help: D
source share