Output Export to excel - sql-server

We having SQL Server Management Studio , we had written several stored procedures in it. Currently we taking output in HTML and mailing to desired email id's. Now our requirement is instead of HTML we need to take output in excel and mail to desired Id's.

I would use the SQL Server Reporting services, and add subscriptions that send the created result by email as an Excel or CSV file.

Excellent question.
As Michael mentioned, you may use SQL Server Reporting Services (SSRS) to create a report that automatically sends the excel file to your chosen subscribers.
This might be an ideal solution if:
Your business unit would like the report to have specific fonts, color schemes, and column formatting as this is a user-friendly way to format the report and test as needed prior to adding on the email subscriptions. Of course, this depends on your audience and the way that the excel file might be used.
You have support analysts or specialists on your team that have been granted access to SSRS, but not necessarily SQL Server Management Studio. From my experience, granting access to one but not the other may lessen the liability of stored procedures or tables being written over, deleted, executed improperly, etc.
Your business unit frequently has changes to the subscription list, as you would be able to hand the responsibility of editing the list over to designated user-support team members rather than bogging down your SQL Developers.
However, if you'd prefer to create a stored procedure to send the emails or don’t have access to SSRS, then you should be able to use the Bulk Copy Program (BCP) command-line utility to generate a simple CSV file. Here are a couple of resources that provide further detail on this option:
https://www.red-gate.com/simple-talk/sql/database-administration/creating-csv-files-using-bcp-and-stored-procedures/
https://social.msdn.microsoft.com/Forums/sqlserver/en-US/453c9593-a689-4f7e-8364-fa998e266363/how-to-export-sql-data-to-excel-spreadsheet-using-sql-query?forum=transactsql
If you have any further questions, please don’t hesitate to reach out! I’m always happy to help whenever I’m able.

Related

SSRS report with different data

I have an SSRS report where I receive a table of files which stuck in transition. In that table may be more than one user who should do some action. I want to create one report and change (using SQL query) the user for whom this table generated and send personalized reports to them. We are using MS SQL Standard 2014. So I've found a workaround on how to generate a data-driven subscription and it works fine. But reports which will send by RS still contain information for all users. I mean report which contains all people who should do some stuff is sending only for people mentioned in this report, not to all users in the base. Because of this, it's not usable and it really hard to find which files belong to you.
I'm stuck on the step: Is it possible for each iteration of running the same report to use different user names to generate personalized reports? For example except this, I want users will receive that.
For data-driven subscription I used this instruction.
I know the simple way is to create many reports for one user and trigger it, but I think it's monkey business.
Thank's to Tyron78. I tried SSIS and it 100% what I needed.
I've built a small workflow with SQL query and c# script. c# script generates pdf files and sends them to a list of users which emails users get from SQL query.

How to access the data base behind IBM Cognos Report Studio

We are using the IBM Cognos Report Studio for Making the Reports.
And we have 1000s of reports developed and using.
Now i need to fetch all the SQL queries written in these 1000+ reports.
For that at present i am opening the report studio for each individual report and getting the query.
But it is very tedious job and taking months to get all the SQLs in these 1000+ reports.
So i am looking for a way to get all these queries from database behind Cognos studio.
Does these report parameters (including the SQL) store in a Database or only in Contentstore?
If it store in DB then is it possible to access the Report Studio in a Database tool like Oracle SQL Developer?
So that i can fetch all the SQLs in one shot from the database table.
Thanks for the help!
My experience migrating from one reporting product to another is like what you are asking. I think I had 7000 reports that I was aware of plus many reports sitting on workstation hard drives. At some point along the way we realized that the new product had different features than the old one, so report redesign was a good option in most cases. It took 18 months once we actually started working on the reports. That was to replace the 700 "standard" reports. Users were on their own (with support from IT and subject matter experts) for their custom work. I now have about 19,000 reports in Cognos.
Except where the report developer wrote SQL in a SQL object in the Queries area, Cognos reports do not contain SQL code. Cognos generates the SQL at runtime based on the report spec and user interaction (what parameters they set, what page the opened, etc.). Short of writing your own report spec parser, duplicating the work that Cognos does for you, there is no way I know of to generate the SQL.
One possibility: I haven't dug too deeply into the Cognos SDK. There may be a method there to generate the SQL for each report. Then you can do it automatically. Be aware that for thousands of reports you'll want to run this process during non-work hours. It could run for hours and may use a lot of resources.
Another possibility: Turn on native query logging (Cognos Administration | System | All dispatchers | | Set properties | Settings | Logging | Check the boxes for "Audit the native query..."). Then have a person, a product like those from Motio, or a Cognos SDK program you create yourself run every report. Then you can get the SQL from the Audit database. Of course, the problem here is answering prompts. It will probably take a person to run these.
To add two columns to a list, or two data elements to a report or page header or footer, or two filters (I don't know what you mean by "clause"), you'll want to use the Cognos SDK.
Choose relevant examples of different types of reports.
Examine the XML report spec for each of those reports.
Determine how to identify where the new element should appear in the XML.
Write a program (probably in C# or Java) to use the SDK to...
inspect every report in your environment.
determine which pattern the report fits.
add the data elements.
save the report.

SQL Server Reporting Services - Ability to trigger report generation from stored procedure

I'm just starting to explore the Visual Studio Reporting Services and, before I dive deep into the details, I need to know if the following is feasible.
I have a web application that, through a SERVLET, interacts with a SQL Server database (2012).
Now, I need to realize a scenario in which a user (Web Client) clicks on a button, a report is created at the Server's side and a link to the report is returned (so that the user may download it).
The reports could be either in Excel or PDF format.
Since I have an active and perfectly working interface with the database, I would like to have this scenario using the same mechanisms, meaning invoke a stored procedure that would trigger the report generation (to be stored in a pre-defined folder with a pre-defined name).
My questions are:
Is this at all possible?
If yes, could anyone provide some guidelines on how to tackle this in the right way?

Can I automatically export data from a Cognos report into a database?

The overall goal is to have data from an automated daily Cognos report stored in a database so that I am able to report not only on that day but also historical data if I so choose. My general thought is that if I can find a way to automatically add the new daily data to an existing Excel file, I can then use that as my data source and create a dashboard in Tableau. However, I don't have any programming experience, so I'm floundering here.
I'm committed to using Tableau, but I chose Excel only because I'm more familiar with that program than others, along with the fact that an Excel output file is an option in Cognos. If you have better ideas, please don't hesitate to suggest them along with why you believe it's a better idea.
Update: I'm still jumping through hoops to try to get read-only access to the backend database to make this process a lot more efficient, but in the meantime I've moved forward with the long method utilizing Cognos.
I was able to leverage a coworker to create a system file folder to automatically save the Cognos reports to, and then I scheduled a job to run the reports I need. Each of those now saves into a folder in a shared network drive (so my entire team has access to the files), and I wrote a series of macros to append the data each day from those feeder files in the shared drive to a Master File. Now all that's left is to create a Tableau dashboard using the Master File as the data source and I'll have what I need.
Thanks for all your help!
I'm posting this an an answer because, it's just too much to leave as a comment.
What you need are 3 things.
Figure out how to have COGNOS run your report and download your Excel file.
Use Visual Studio with BIDS (which is the suite of SQL analysis, reporting, and integration services) to automate all the stuff you need to do to append your Excel files, etc... Then you can use the same tools to import that data to your SQL server.
In fact, if all you're doing is trying to get this data into SQL, you can skip the Append Excel part, and just append the data directly to your SQL table.
Once your package is built, you can save it as an automated job on your SQL server to run whenever you wish.
Tableau can use your SQL server as a data source. Once you have that updated, you can run your reports.

User-friendly tools for retrieving data from a SQL Server database

We have several SQL Server databases containing measurements from generators that we build. However, this useful data is only accessible to a few engineers since most are unfamiliar with SQL (including me). Are there any tools would allow an engineer to extract chosen subsets of the data in order to analyze it in Excel or another environment? The ideal tool would
protect the database from any accidental changes,
require no SQL knowledge to extract data,
be very easy to use, for example with a GUI to select fields and the chosen time range,
allow export of the data values into a file that could be read by Excel,
require no participation/input from the database manager for the extraction task to run, and
be easy for a newbie database manager to set up.
Thanks for any recommendations or suggestions.
First off, I would never let users run their own queries on a production machine. They could run table scans or some other performance killer all day.
We have a similar situation, and we generally create custom stored procedures for the users to "call", and only allow access to a backup server running "almost live" data.
Our users are familiar with excel, so I create a stored procedure with ample parameters for filtering/customizations and they can easily call it by using something like:
EXEC YourProcedureName '01/01/2010','12/31/2010','Y',null,1234
I document exactly what the parameters do, and they generally are good to go from there.
To set up a excel query you'll need to set up the data sources on the user's PC (control panel - data sources- odbc), which will vary slightly depending on your version of windows.
From in excel, you need to set up the "query", which is just the EXEC command from above. Depending on the version of Excel, it should be something like: menu - data - import external data - new database query. Then chose the data source, connect, skip the table diagram maker and enter the above SQL. Also, don't try to make one procedure do everything, make different ones based on what they do.
Once the data is on the excel sheet, our users pull it to other sheets and manipulate it at will.
Some users are a little advanced and "try" to write their own SQL, but that is a pain. I end up debugging and fixing their incorrect queries. Also, once you do correct the query, they always tinker with it and break it again. using a stored procedure means that they can't change it, and I can put it with our other procedures in the source code repository.
I would recommend you build your own in Excel. Excel can make queries to your SQL Server Database through an ODBC connection. If you do it right, the end user has to do little more than click a "get data" button. Then they have access to all the GUI power of Excel to view the data.
Excel allows to load the output of stored procedures directly into a tab. That IMO is the best way: users need no knowledge of SQL, they just invoke a procedure, and there are no extra moving parts besides Excel and your database.
Depending on your version of SQL server I would be looking at some of the excellent self service BI tools with the later editions such as Report Builder. This is like a stripped down version of visual studio with all the complex bits taken out and just the simple reporting bits left in.
If you setup a shared data source that is logging into the server with quite low access rights then the users can build reports but not edit anything.
I would echo the comments by KM that letting the great unwashed run queries on a production system can lead to some interesting results with either the wrong query being used or massive table scans or cartesian joins etc

Resources