Go Premium for a chance to win a PS4. Enter to Win

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 1368
  • Last Modified:

How To Create a PDF from a stored procedure

is there a way i can write a stored procedure in sql server to generate a sql result in a
PDF  or excel file??  (sql server db 2012)
0
eoswin
Asked:
eoswin
  • 2
1 Solution
 
ZberteocCommented:
No. In SQL Reporting Services you have the option to convert any report in excel or in PDF format but directly from SQL server in a stored procedure is not the place and it was never meant to be. This should be done from an application.

You can however export in CSV format a result set, which can be easily opened in Excel. You can find a lot of examples on the net.
0
 
smiliefaceCommented:
You can make it export to Excel using something like this
INSERT INTO OPENROWSET 
   ('Microsoft.Jet.OLEDB.4.0', 
   'Excel 8.0;Database=c:\MyFile.xls;','SELECT Name, City, Zip FROM dbo.Customer')

Open in new window


You can also use BCP to create a CSV file and open that in Excel.

PDF is harder, but I'm sure there are way to do it using a CLR and running the output of a query through a converter.
0
 
ZberteocCommented:
What was wrong with my answer?
0

Featured Post

Keep up with what's happening at Experts Exchange!

Sign up to receive Decoded, a new monthly digest with product updates, feature release info, continuing education opportunities, and more.

  • 2
Tackle projects and never again get stuck behind a technical roadblock.
Join Now