How do I write a query in Microsoft SQL Server Management Studio and then use that Query in Excel

Solution 1:

I do the following steps when I want to paste in a SQL Server query: (assuming Excel 2007)

  1. Data > From Other Sources > From SQL Server
  2. Enter server name
  3. Choose the database you want and select a small table from the list of tables.
  4. Hit OK
  5. With the Table Tools>Design tab selected, click the arrow under Refresh, click Connection properties.
  6. Click Definition
  7. Change Command Type to 'SQL'
  8. Paste in your query in the 'Command Text' box. Hit OK.

That has always worked for me.