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)
- Data > From Other Sources > From SQL Server
- Enter server name
- Choose the database you want and select a small table from the list of tables.
- Hit OK
- With the Table Tools>Design tab selected, click the arrow under Refresh, click Connection properties.
- Click Definition
- Change Command Type to 'SQL'
- Paste in your query in the 'Command Text' box. Hit OK.
That has always worked for me.