Solved

How To Create a PDF from a stored procedure

Posted on 2014-02-20
3
1,143 Views
Last Modified: 2014-02-24
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
Comment
Question by:eoswin
  • 2
3 Comments
 
LVL 26

Expert Comment

by:Zberteoc
ID: 39874978
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
 
LVL 3

Accepted Solution

by:
smilieface earned 500 total points
ID: 39875603
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
 
LVL 26

Expert Comment

by:Zberteoc
ID: 39883040
What was wrong with my answer?
0

Featured Post

Best Practices: Disaster Recovery Testing

Besides backup, any IT division should have a disaster recovery plan. You will find a few tips below relating to the development of such a plan and to what issues one should pay special attention in the course of backup planning.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

There have been several questions about Large Transaction Log Files in SQL Server 2008, and how to get rid of them when disk space has become critical. This article will explain how to disable full recovery and implement simple recovery that carries…
SQL Server engine let you use a Windows account or a SQL Server account to connect to a SQL Server instance. This can be configured immediatly during the SQL Server installation or after in the Server Authentication section in the Server properties …
A short tutorial showing how to set up an email signature in Outlook on the Web (previously known as OWA). For free email signatures designs, visit https://www.mail-signatures.com/articles/signature-templates/?sts=6651 If you want to manage em…
In an interesting question (https://www.experts-exchange.com/questions/29008360/) here at Experts Exchange, a member asked how to split a single image into multiple images. The primary usage for this is to place many photographs on a flatbed scanner…

820 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question