How to add an existing query to a new query in the SQL Pane in SQL server

When developers create a query, they are retrieving data from a table or other objects structured like tables — views and certain user-defined functions. To work with any of these objects in their query, they add them to the Diagram Pane.When developers working with SQL Server “Denali”, MS SQL Server 2008 R2 and MS SQL Server 2005 want to add an existing query, they should follow the next steps:

1. Make sure the SQL Pane is displayed in the new query they are creating.

2. In the SQL Pane, type a right and left parentheses () after the word FROM.

3. Open the Query Designer for the existing query. (They now have two Query Designers open.)

4. Display the SQL Pane for the inner query – the existing query they are including in the new, outer query.

5. Select all the text in the SQL Pane, and copy it to the Clipboard.

6. Click in the SQL Pane of the new query, situate the cursor between the parentheses they added, and paste the contents of the Clipboard.

7. Still in the SQL Pane, add an alias after the right parenthesis.