Executing Stored Procedures in SQL with automatic date - sql

There is a software (called StackVision) that uses "SQL Server Reporting Services" for creating some reports. More information about the software is here.
I am trying to make a new "View" out of a couple of "Stored Procedures" in the database. I do not want to mess with the stored procedure coding though. I just want to run a code to build a new "View" out of the results of "Stored Procedures." The following code can run one of the desired stored procedures.
EXECUTE [dbo].[ss_Total]
#StartDate ='07/1/2020'
, #EndDate='09/30/2020 23:59'
, #ParameterA='AA'
, #ParameterB='BB'
,#INterval = '001H'
Does anyone know who I can execute the following "Stored Procedure" only on last quarter. Instead of putting a certain date (such as '07/1/2020' and '09/30/2020 23:59'), I would like to have a coding that tells the stored procedure to be conducted from the beginning of last quarter to the end of last quarter. Assume that the date is 10/2/2020.
BTW, the software also run the stored procedures to create some reports.
The reason that I am doing this:
I built a Power BI report by connecting the Power BI report to the Stackvision server. The Power BI report, calls/runs the stored procedures and then append/merge tables to create a report. Unfortunately, the Power BI server fails to refresh the data. So, I am thinking to create one "view" in the database and only pull that view into Power BI. Then the Power BI server will not time out and will not fail anymore.

You can add the date 3 months from your initial param.
here the link:
https://www.w3schools.com/sql/func_sqlserver_dateadd.asp
I don't know what your DB using, if you using MySQL try this for example
SELECT ADDDATE(NOW(), 90) as datethis

Related

IBM SPSS How to import a Custom SQL Database Query

I am looking to see if the capability is there to have a custom SSMS sql query imported in SPSS (Statistical Package for the Social Sciences). I would want to build syntax that generates this query as my new dataset that I can then continue my scripted analysis. I see the basic query capability of one table from a Sql Server but I would like to create a query that joins to many tables. I anticipate the query to be a bit complex with many joins and perhaps data transformations.
Has anybody had experience or a solution to this situation?
I know I could take the query and make a table of it that SPSS can then connect to but my data changes daily and I would need a job in another application to refresh this table before my SPSS syntax would pull it and I would like to eliminate that first step by just having the query that grabs the data at the beginning of my syntax.
Ultimately I am looking to build out my SPSS syntax and schedule it in the Production Facility to run daily.

Teradata SQL & cognos. How can I customize Cognos to accept a customized & more efficiently performing SQL

RIght at the outset I'd like to say that I am NOT a Cognos Guy .So I have totally disconnected myself from developing cognos cubes / reports whatever you want to call it.
There are COGNOS queries auto generated - very badly written that will cause the Teradata ( DBS 15.1.x ) system to Hog on spool & CPU . I can tune them beautifully after I pull them out from DBQL. I want to know HOW can I implement Custom Queries that can be run periodically as batch reports instead of Cognos auto-generating these queries.
E.g. You create a cube - its writes code behind it and then you can open the code and write custom code that is equivalent to the original code but performs a lot better. Then when you open the cube again - it remembers there is a custom SQL and runs that instead of its own auto generated SQL . This is just how I imagine one way it can do it but again- I am not a cognos resource so pl dont flag me down for lack of knowledge. That is exactly what I am trying to get an idea about
Thanks for bearing with me
In Framework Manager you can create one Query Subject with complex query inside. Do not import tables etc. Just create QS in put your query inside.
You need to use stored procedure to return your expected data and add it to Model.
Then instead of using couple of tables in Cognos report studio (and joins), add one query and point it to your stored procedure. This way your Cognos report will execute the procedure instead of generating query (which may not be efficient in many cases)

How to use SQL Server stored procedures in Microsoft PowerBI?

I want to generate reports from my SQL Server tables.
I have some already made stored procedures that I would like to use to generate reports from.
I haven't found a way to do so.
Only by rewriting the queries.
Thanks :)
To execute your SP in Power BI-->
1.In SQL Server right click on your SP and select Execute. Your code is executed and a new query window opens up which was responsible for execution. Copy that Query.
2.In Power BI Query Editor, select New Source-->SQL Server. After giving the server and database, in the same window click on "Advanced Options", paste the query in the "SQL Statement" that opened up.
Check "Navigate using full hierarchy" and click OK.
3.You will see data for the parameters you passed in SP only.
On Applying these changes, you will see the dataset for this in Power BI Desktop from where you can create reports.
NOTE: This works in"Import Query" option.
Hope this works for you as it did for me, Cheers!
You can use openquery. The following syntax will work with both import data and direct query methods in Power BI Desktop.
SELECT *
FROM OPENQUERY ([server name],
'EXEC dbname.dbo.spname #parametername = ''R1''');
Expand the Advanced options in the Get Data -> SQL Server dialog, and write a SQL Statement to execute your stored procedure such as:
EXEC [dbo].[usp_NameOfYourStoredProcedure]
Firstly I think its best to make the point out that Power BI isn't Reporting Services, it expects to be given existing table data or views that you then model within it's own environment before creating your dashboards.
If you can get Power BI to do the work of your stored procedures. Once you have your data model defined within Power BI it can be reused.
There is a great introduction course for this on the Power BI website:
https://powerbi.microsoft.com/en-us/guided-learning/powerbi-learning-2-1-intro-modeling-data/
"Hi,
In an Excel workbook, open the ""Power Query"" tab.
Then choose the “From Database” drop down button and select “From SQL Server Database”
Fill in the Server and Database textboxes and click OK
In the Navigator window, double-click the desired table
In the Query Editor window, click on to the column to be displayed.
Click close and select the ""Load"" button
Connect to stored procedures.
Create another power window and fill in the server and database textboxes.
In the SQL statement textbox, type “EXECUTE  Procedure_Name”
Click Close and Load button
"

Reuse of SSRS Report parameter

I am new to SSRS, I am creating a report which will take ID's as parameter e.g. 1,2,6,7,8,9 and so on. This parameter will be used for multiple reports. As a good practice I am thinking the user should not enter the ID for each report. Once entered/selected the ID parameter should be persistent for all the reports.
I am using Visual Studio 2008 to create the report and SQL Server 2008 R2 for backend scripting.
This can be done in an elegant way, but requires some work on the back end database.
If your reports are executing stored procedures, you can have the stored procedure for each report write the user's choice of a parameter to a table. Then the next report can check that table for a value. You could design this to be user specific, time-dependent, etc., depending on the effort you put in. It might be cleaner to set the parameter in a separate dataset. That is, in each report, you have multiple datasets. One grabs the parameter value, and your report parameters will default to that result. The other report data set can display the "main data."

How To use a stored procedure in a crystal reports 8.5?

I have to make a new report using crystal report8.5 .
I have created a stored procedure in SQL Server 2005. The stored procedure has one input parameter.
Now I wanna to know that how I can add that stored procedure and show its result in my report
while designing that report?
thank you
First go to File > Options > Database (going from memory) and make sure the checkbox for Stored Procedures is ticked. Then, when you setup your connection to SQL Server, as well as a Tables section you'll see a Stored Procedures one beneath it. Find your stored procedure in the list, add it as the data source for your report, and you'll be able to use it as a normal source.