hello, i have this stored producer that union many tables and i want to order by apartemetnnoen as u see down and still give me error near union
What I have tried:
SELECT
[Spare6]
,[Spare5]
,[Spare4]
,[Spare3]
,[Spare2]
,[Spare1]
,[details]
,[note]
,[documents]
,[termsofpaymneten]
,[termsofpaymnet]
,[aprtmentstatusen]
,[aprtmentstatus]
,[amountdateen]
,[amountdate]
,[amountleft]
,[amountpaid]
,[rent]
,[noofpayemtsen]
,[noofpayemts]
,[sourceen]
,[source]
,[iddateen]
,[iddate]
,[idnumber]
,convert(datetime, contractenen, 111) as contractenen
,[contracten]
,[contractstarten]
,[contractstart]
,[contractnoen]
,[contractno]
,[nationalityen]
,[nationality]
,[secondpartyen]
,[secondparty]
,[firstpartyen]
,[firstparty]
,[apartemetnnoen]
,[apartemetnno]
,[Bulidingnoen]
,[Bulidingno]
,[No] FROM [All_Vech].[dbo].[Bulding_Sharfya]
WHERE [idnumber] LIKE '%' + @idnumber + '%' OR [Bulidingno] Like '%' + @Bulidingno + '%' OR [Bulidingnoen] LIKE '%' + @Bulidingnoen + '%' OR [apartemetnno] LIKE '%' + @apartemetnno + '%' OR [apartemetnnoen] LIKE '%' + @apartemetnnoen + '%' OR secondparty LIKE '%' + @secondparty + '%' OR secondpartyen LIKE '%' + @secondpartyen + '%' OR nationality LIKE '%' + @nationality + '%' OR nationalityen LIKE '%' + @nationalityen + '%' OR [contractno] LIKE '%' + @contractno + '%' OR [contractnoen] LIKE '%' + @contractnoen + '%' OR [contracten] Like '%' + @contracten + '%'
ORDER BY apartemetnnoen DESC;
UNION