Tariq, here's your immediate problem.
When you query from a subquery, you need to provide it with an alias at the end.
Here's a very simple example. The following won't work and will give you the same error that you're receiving:
select * from (select * from Purchasing.Vendor)
However, if you give it a table alias at the end...
select * from (select * from Purchasing.Vendor) TableAlias
Then it will work.
Now - after you verify that it solved your problem, I'd like to talk about the rest of your query. Even if it runs without an error, there are some potential problems down the road.
Kevin