0

I want to export the result of a stored procedure execution to a excel worksheet,I want to set this up as a Job which will generate the result and store it in a excel worksheet.Is this possible I have googled it but not found any convincing workable solutions

joel
  • 183
  • 1
  • 3
  • 15

1 Answers1

1

You can use INSERT INTO OPENROWSET, for example:

INSERT INTO OPENROWSET ('Microsoft.Jet.OLEDB.4.0', 'Excel 8.0;Database=D:\Output.xls;', 'EXEC   [dbo].[spName] ''param''') EXEC [dbo].[spName] 'param'

You should enable Ad Hoc Distributed Queries before:

EXEC sp_configure 'show advanced options', 1
RECONFIGURE
GO
EXEC sp_configure 'ad hoc distributed queries', 1
RECONFIGURE
GO
Saber
  • 2,440
  • 1
  • 25
  • 40