How to call a stored procedure and return just the first result set from within another stored procedure in SQL Server 2019? - sql-server-2019

We are using SQL Server 2019, and have an existing stored procedure which returns two result sets.
I am trying to build a new stored procedure which will call this procedure and store the data from its first result set in a temporary table so it can be used, but I can't seem to find a way to do this.
Changing the first stored procedure is not an option, and I would prefer not to duplicate it as that would mean maintaining two versions and would almost inevitably lead to problems later on.
Does anyone know how to do this?

Related

T-SQL - Insert set into multiple constrained tables on linked server

So, I have a data set on server "A" and two tables ("t1", "t2") on linked server "B".
I cannot modify server "B" schema.
What I am trying to achieve is: insert first two data set (non-identity) columns into [B].[t1] which should generate identity index value, and then add second two, also non-identity, columns into [B].[t2], which contains column MsgId that should map to corresponding row in [B].[t2].
A visual version of how it works
It seems that I cannot use OUTPUT nor SCOPE_IDENTITY() on a linked server (both return nothing).
My question is so: Is there a way to add data from server A to server B without modifying latter?
My current solution involves cursors and creating a stored procedure on a remote server, but I feel like I am doing it completely wrong and reinventing wheel in the process. Also, modifying database structure is a painful process involving lots of paperwork.
What you want to do is ETL (Extract, transform, load) and using a tool like SSIS helps to do that much cleaner and more maintainable.

SSIS or TSQL for SQL/MySQL table comparrison

I am new to SSIS and am after some assistance in creating an SSIS package to do a specific task. My data is stored remotely within a MySQL Database and this is downloaded to a SQL Server 2014 Database. What I want to do is the following, create a package where I can enter 2 dates that can be compared against the create date/date modified per record on a number of tables to give me a snap shot and compare the MySQL Data to the SQL Data so that I can see if there are any rows that are missing from my local SQL Database or if any need to be updated. Some tables have no dates so I just want to see a record count on what is missing if anything between the 2. If this is better achieved through TSQL I am happy to hear about other suggestions or sites to look at where things have been done similar.
In relation to your query Tab :
"Hi Tab, What happens at the moment is our master data is stored in a MySQL Database, the data was then downloaded to a SQL Server Database as a one off. What happens at the moment is I have a SSIS package that uses the MAX ID which can be found on most of the tables to work out which records are new and just downloads them or updates them. What I want to do is run separate checks on the tables to make sure that during the download nothing has been missed and everything is within sync. In an ideal world I would like to pass in to a SSIS package or tsql stored procedure a date range, shall we say calender week, this would then check for any differences between the remote MySQL database tables and the local SQL tables. It does not currently have to do anything but identify issues, correcting them may come later or changes would need to be made to the existing sync package. Hope his makes more sense."
Thanks P
To do this, you need to implement a Type 1 Slowly Changing Dimension type data flow in SSIS. There are a number of ways to do this, including a built in transformation aptly called the Slowly Changing Dimension transformation. Whilst this is easy to set up, it is a pain to maintain and it runs horrendously slowly.
There are numerous ways to set this up using other transformations or even SQL merge statements which are detailed here: https://bennyaustin.wordpress.com/2010/05/29/alternatives-to-ssis-scd-wizard-component/
I would recommend that you use Lookup transformations as they perform better than the Slowly Changing Dimension transformation but offer better diagnostics and error handling than the better performing SQL merge statement.
Before you do this you will need to add a Checksum or Hashbytes column to your SQL data for ease of comparison with the incoming MySQL data.
In short, calculate some sort of repeatable checksum as the data is downloaded into your SQL Server, then use this in an SSIS Lookup, matching on the row key, to check for changes. Where the checksum value is different for the same row it needs updating and where there is no matching row key in your SQL Data you need to insert the new row.

Calling Stored Procedures from Microstrategy

We have a stored procedure that takes in a set of parameters (from dimension tables) and then outputs a set of rows from which a report has to be created.
Till now this is done in a .NET app using an ORM, but is it possible to integrate it with MicroStrategy?. How do I pass the selected params (from a report prompt) to a Stored Procedure on the database and then map the results back to the report?
In the past I did a Free Form SQL (FFSQL) report in MicroStrategy on top of a PL/SQL function which returned a 'table' (Of course that was an Oracle database, more info about returning a table with a function here).
So what you are looking for is something doable.
You can use the prompts in FFSQL report as parameters for your function
Then you have to map the columns of the returned table as attributes and metrics returned by the FFSQL report
This is something I did in a very old MicroStrategy implementation to provide writeback functionality: the users were allowed to update some values in some tables and the function returned a Success or Error message.
As you can imagine this was not a standard Data Warehouse solution, it was more an hoc solution for an operational database.
My suggestion is to avoid similar solution if not necessary and prepare in advance the tables/rows that you need. Of course in your case you have already the procedure ready so you have just to figure out how to combine it with MicroStrategy.
Some useful readings:
TN37783: Instructions to use stored procedures within Freeform SQL reports in MicroStrategy 9.x against different databases
Using Prompts in Freeform SQL Reports

How to execute reports which involve a stored procedure calling out to a linked server

I wrote a stored procedure that calls openquery to a linked server to get data from a remote postgresql server and fill a table with that data. This is working fine. The stored procedure needs 3 parameters.
When I try to call the stored procedure from Report Builder 3.0 gives me error
7350 (cannot get the column OLE DB provider MSDASQL from linked server "name").
I already verify the allow in-process parameter in MSDASQL.
I can't find a solution for this. If I run the stored procedure from Mgmt Studio, it works fine. I'm using SQL Server 2012.
The report only have to show the file data by row. I can run the stored procedure and the report separately and works but I have to do this manually, my requirement needs a report subscription, so have to be automatic.
Any idea how to solve this or a workaround?
PD: sorry for my english, and thank you in advance.
Well I had to make separates works, so create a job that run the store procedure, generate the info on a table, and then run report reading the info from the table. This works.
Thank you all.

SSRS 2008 - refresh report without requerying data?

I have four parameters on my report. Three of them are required for the underlying stored procedure data source, but the fourth parameter is just used to show/hide items on the report.
If the user changes the value for that fourth parameter, is there a way to refresh the report using the existing data without running the stored procedure again? The result set won't change, only the rows that are to be displayed.
Reporting Services 2008 seems to treat each combination of report parameters as a unique set, even if some of them are internal to the report only, and not related to the stored procedure. Therefore, aside from using report caching, there is no way to prevent report server from making a round trip to the database, even if only the internal parameter changes. You basically have two options:
Turn on report caching in report server, and run all combinations of
the four parameters, so that the user will be accessing report
server's cache when she runs any report. This avoids making a round trip to the database, but only for the parameter values you've already tried.
write your underlying stored procedure with caching behavior so that it writes its results to a database table. Whenever the stored procedure is run, have it first check the table to see if the results for the current set of parameter values is already stored in the cache table, and if so return those rows to report server. This still requires a round trip, but it is faster than running the procedure again.