Solved

How To Create a PDF from a stored procedure

Posted on 2014-02-20
3
1,098 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

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
powershell and sql server - alerting 7 77
Minus first query 1 36
SQL Query 2 43
Need a SQL Server 2014 plug-in to scan the DB schema 4 19
Occasionally there is a need to clean table columns, especially if you have inherited legacy data. There are obviously many ways to accomplish that, including elaborate UPDATE queries with anywhere from one to numerous REPLACE functions (even within…
How to leverage one TLS certificate to encrypt Microsoft SQL traffic and Remote Desktop Services, versus creating multiple tickets for the same server.
This tutorial gives a high-level tour of the interface of Marketo (a marketing automation tool to help businesses track and engage prospective customers and drive them to purchase). You will see the main areas including Marketing Activities, Design …
Hi friends,  in this video  I'll show you how new windows 10 user can learn the using of windows 10. Thank you.

867 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

Need Help in Real-Time?

Connect with top rated Experts

16 Experts available now in Live!

Get 1:1 Help Now