sql - How to export the results of a stored procedure directly to a MS Excel file? -


text after "itemprop =" text ">

I found a way to extract the content of an MS SQL table to get the (sharp) excellence directly. But I do not know how to do this with a stored procedure that requires parameters, is it possible to extract the results of a stored procedure in Excel? I know how to do this indirectly (using the data table), but it is very slow Thanks a lot.

PS: This is the method that I was using to do some tests. It works with a table, but what I need to do is to get the result of a stored procedure:

  private sub SqlToExcelTest2 (ByVal excelFilePath as string, _ ByVal nonExistingSheetName string In the form of _ ByVal as the SQLServer string, _ ByVal sqlDatabase string, _ ByVal as sqlUserName string, as _ ByVal sqlPassword string, as _byVal as sqlTable string) excelConnStrTemplate string = "Provider = As Microsoft.Jet.OLEDB.4.0, data Source = {0}; Expanded Properties = "" Excel 8.0; HDR = Yes; IMX = 2 ";" connStr Dim String = String.Format (excelConnStrTemplate, _ excelFilePath) Const as adoQueryTemplate String = "as Select * Execution {0} from [ODBC, Driver = {{SQL Server}}, "& Amp; _ "Server = {1}; database = {2}; uid = {3}; pwd = {4}]. [[5}]" slow query string = string.format (endowttttpplate, _nonfinestinationgate name, _sqlServer , _ SqlDatabase, _ sqlUserName, _ sqlPassword, _ sqlTable) using OleConn as new OleDb.OleDbConnection (connStr), oleCmd as new OleDb.OleDbCommand (query, olecon) oleConn.Open () oleCmd.ExecuteNonQuery ( ) After the end sub  

I check No need for Excel yet, but You can try:

  1. Start a new worksheet recording
  2. Select Menu> Data-> Import, and some like "Data Source"
  3. Select your choice table / (I'm not sure if the stored procedure is also supported)
  4. Setup all credits view etc.
  5. Follow the rest of the steps ...
  6. Stop the recording macro

and take a look at the generated VBA code.

If you always run the same query (or something different), then create a data source with some auto-refresh at startup May be required.


Comments

Popular posts from this blog

c++ - Linux and clipboard -

What is expire header and how to achive them in ASP.NET and PHP? -

sql server - How can I determine which of my SQL 2005 statistics are unused? -