MySQL Stored Procedure in SSIS destination - mysql

Is it possible to use MySQL stored procedure in DataFlow task destination?
While SQLServer is the source, MySQL DB is the destination, and I would like to use stored procedure to normalize the data. Currently the process uses ADO NET Destination with ADO.NET connection manager to insert data into a single table and it works.

Well, Yes you can use it. But take care about Connection of MySQL and Parameters you passed to Stored Procedure.
Current System and use of StoredProcedure both will work for same.

You can't use a stored procedure as a destination, but you can use a staging table as a destination and then call a stored procedure that normalizes your data as it sends it to the destination tables.

Related

Can we connect Cosmos DB to SSRS?

I have to use Azure Cosmos DB in SSRS reports. I have used ODBC connector. I am able to fetch data using simple select query. But not able call stored procedure or function in SSRS reports. Is it possible to call Cosmos DB stored procedure in SSRS like?
Cosmos DB not being a relational database and its procedures being written in Javascript are irrelevant factoids in the context of the question.
There are ways you could directly and indirectly query data in Cosmos via a stored procedure in SQL Server which in turn could be used as the datasource for SSRS reports.
1) Write a Python script that connects to Cosmos DB, queries the data you're looking for into JSON documents, and writes these to a file https://learn.microsoft.com/en-us/azure/cosmos-db/sql-api-python-samples.
If this query in Cosmos requires scanning documents in multiple partitions you can enable cross partition queries. "To run a query across partitions, set EnableCrossPartitionQuery to true (or x-ms-documentdb-query-enablecrosspartition in the REST API)"
https://learn.microsoft.com/en-us/azure/cosmos-db/how-to-query-container
2) Create a stored procedure in SQL Server. Use xp_cmdshell in the SQL Server stored procedure to execute the Python script in step 1. Or you can create an agent job in SQL Server with a powershell step -- and the stored procedure can execute this job.
https://learn.microsoft.com/en-us/sql/relational-databases/system-stored-procedures/xp-cmdshell-transact-sql?view=sql-server-ver15
Run Python Script from MSSQL
Use BULK INSERT in the procedure to insert the JSON data in the file into a table in SQL Server -- then use the T-SQL OPENJSON function to parse the JSON into columnar form.
https://learn.microsoft.com/en-us/sql/t-sql/functions/openjson-transact-sql?view=sql-server-ver15
3) Add the stored procedure as the datasource for an SSRS report.
If you're using the MongoAPI you could also directly query Cosmos using Polybase in SQL Server 2019.
https://learn.microsoft.com/en-us/sql/relational-databases/polybase/polybase-configure-mongodb?view=sql-server-ver15
Connect Cosmos DB to SQL using Cosmos DB ODBC Connector.
https://learn.microsoft.com/en-us/azure/cosmos-db/odbc-driver#connect
Create a stored procedure to call Cosmos object using OPENQUERY command like below.
Select * FROM OPENQUERY( select * from [CosmosDB].[Table] )
https://www.sqlshack.com/link-an-azure-cosmos-db-into-a-sql-server-stored-procedure/
Once having the stored procedure, it should be easy to use it in SSRS.
Cosmos DB is not a relational database, and its stored procedures are not the same thing as a SQL Server stored procedure (and there is no SQL in a Cosmos DB stored procedure; only JavaScript, executing against the documents within a specific partition).
You cannot call a Cosmos DB stored procedure from SSRS. You can only invoke a Cosmos DB stored proc via SDK (or REST API) call.

SSIS ETL execute MySQL Stored procedure on Destination Server

I am working on an SSIS ETL and I wanna know if there is a possibility to execute a MySQL Stored Procedure.
Here is what I want to do : From an SQL Server Database, I want to get Information by an ETL (SSIS) and send them to a MySQL Database (by a stored procedure)
Here is what I have done so far : I get my data from SQL Server Database and tranform them.
Here where I am stuck : I don't know how to execute an existing stored procedure on the MySQL Server Database (my destination)
Here is my ETL (DATA FLOW) diagram :
I also add an OLEDB provider on the server and add my destination source (MySQL Database) but I don't know what I need to do in my ETL to execute the stored procedure.
I can provide more information if necessary.
Thanks in advance
I am not sure if you mean that you want to execute a stored procedure by passing in every row in memory in SSIS that enters through your multicast. If that is the case, that may be possible with SSIS, but I have never done it.
why not just send the rows to two separate tables in MySQL from the multicast, then go back to the control flow tab and add two execute sql tasks, one for each stored procedure. Change each stored procedure to run on the tables instead of individual rows.
You would probably get a performance boost as well from switching to a set based operation instead of row by row.

Automating tasks on more than one SQL Server 2008 database

We host multiple SQL Server 2008 databases provided by another group. Every so often, they provide a backup of a new version of one of the databases, and we run through a routine of deleting the old one, restoring the new one, and then going into the newly restored database and adding an existing SQL login as a user in that database and assigning it a standard role that exists in all of these databases.
The routine is the same, except that each database has a different name and different logical and OS names for its data and log files. My inclination was to set up an auxiliary database with a table defining the set of names associated with each database, and then create a stored procedure accepting the name of the database to be replaced and the name of the backup file as parameters. The SP would look up the associated logical and OS file names and then do the work.
This would require building the commands as strings and then exec'ing them, which is fine. However, the stored procedure, after restoring a database, would then have to USE it before it would be able to add the SQL login to the database as a user and assign it to the database role. A stored procedure can't do this.
What alternative is there for creating an automated procedure with the pieces filled in dynamically and that can operate cross-database like this?
I came up with my own solution.
Create a job to do the work, specifying that the job should be run out of the master database, and defining one Transact-SQL step for it that contains the code to be executed.
In a utility database created just for the purpose of hosting objects to be used by the job, create a table meant to contain at most one row, whose data will be the parameters for the job.
In that database, create a stored procedure that can be called with the parameters that should be stored for use by the job (including the name of the database to be replaced). The SP should validate the parameters, report any errors, and, if successful, write them to the parameter table and start the job using msdb..sp_start_job.
In the job, for any statement where the job needs to reference the database to be replaced, build the statement as a string and EXECUTE it.
For any statement that needs to be run in the database that's been re-created, doubly-quote the statement to use as an argument for the instance of sp_executesql IN THAT DATABASE, and use EXECUTE to run the whole thing:
SET #statement = #dbName + '..sp_executesql ''[statement to execute in database #dbName]''';
EXEC (#statement);
Configure the job to write output to a log file.

SQL Server stored procedure for inserting multiple rows in one table and single row in other table

I am in need of a stored procedure for sales transaction. In a single SP I need to store CustomerID in one table and list of products purchased (multiple rows) in another table.
Can any one give me an best example?
Thanks in advance.
Table-Valued Parameters is a new feature introduced in SQL SERVER 2008. In earlier versions of SQL SERVER it is not possible to pass a table variable in stored procedure as a parameter, but now in SQL SERVER 2008 we can use Table-Valued Parameter to send multiple rows of data to a stored procedure or a function without creating a temporary table or passing so many parameters.
You can read about it here
for more information about using it with ado
check this great article
SQL Server 2008 Table-Valued Parameters and C# Custom Iterators: A Match Made In Heaven!
well in the stored procedure you can use any many insert commands as you want in any table you want, as your question is not clear enough that i write the exact stored procedure you want, I'm writing an example.
use [databasename]
go
create procedure [dbo].[my_stored_procedure](#customerid int) as
begin
insert into [customerstable](customerid) values (#customerid)
insert into [someothertable](somefieldname1, somefieldname2) values(somefield1value, somefield2value)
insert into [someothertable2](somefieldname1, somefieldname2) values(somefield1value, somefield2value)
end

How do I make a stored procedure in MS Access?

How do I make a stored procedure in MS Access?
Access 2010 has both stored procedures, and also has table triggers. And, both features are available even when you not using a server (so, in 100% file based mode).
If you using SQL Server with Access, then of course the stored procedures are built using SQL Server and not Access.
For Access 2010, you open up the table (non-design view), and then choose the table tab. You see options there to create store procedures and table triggers.
For example:
Note that the stored procedure language is its own flavor just like Oracle or SQL Server (T-SQL). Here is example code to update an inventory of fruits as a result of an update in the fruit order table
Keep in mind these are true engine-level table triggers. In fact if you open up that table with VB6, VB.NET, FoxPro or even modify the table on a computer WITHOUT Access having been installed, the procedural code and the trigger at the table level will execute. So, this is a new feature of the data engine jet (now called ACE) for Access 2010. As noted, this is procedural code that runs, not just a single statement.
If you mean the type of procedure you find in SQL Server, prior to 2010, you can't. If you want a query that accepts a parameter, you can use the query design window:
PARAMETERS SomeParam Text(10);
SELECT Field FROM Table
WHERE OtherField=SomeParam
You can also say:
CREATE PROCEDURE ProcedureName
(Parameter1 datatype, Parameter2 datatype) AS
SQLStatement
From: http://msdn.microsoft.com/en-us/library/aa139977(office.10).aspx#acadvsql_procs
Note that the procedure contains only one statement.