How to Pass Parameters to ORACLE stored procedure in SSIS packages - sql-server

I'm using execute sql task to call a Oracle stored procedure,I want to pass a parameter to a oracle stored procedure
Query Inside Execute sql task:-
BEGIN
PKG_METRICS.GET_STUDY_METRIC(#myparameter, 'FIRST_SITE_SELECTED', 'LAST_SITE_SELECTED', 6, null,'SITE');
END;
Please let me know your comments...

you should go to Expressions in SQL Task,
then add expression to SqlStatementSource
and put this code inside dialog window:
"BEGIN
PKG_METRICS.GET_STUDY_METRIC("+#var_myparameter+", 'FIRST_SITE_SELECTED', 'LAST_SITE_SELECTED', 6, null,'SITE');
END;"
Before that you should add string variable #var_myparameter.

You can build the sql expression as a string as suggested above, but you can also pass parameters to Oracle if they are inputs to the ole db command in the pipeline. Create an OLE DB Command block. In the component properties enter the sql and place ? marks where parameters should be. Next go to input and output properties. Expand OLE DB command Input and add an external column for each parameter you need to pass. Order the MappedColumnId tabs from top to bottom starting with zero. Map them to your inputs on the column mappings tab.
If your parameter is just a parameter in SSIS and not in the pipeline you could either add it to the pipeline with a simple derived column. You can also just execute the proc from a script component using your favorite oracle access dll.
No perfect options, but there are ways to do this!

In addition to chrisPfeif518 :
for Oracle (in my case) , in OLE DB Command task , i used syntax:
{call ... }
for your case should be :
{call PKG_METRICS.GET_STUDY_METRIC(?, ?, ?, ?, ?,?)}

Related

Issue loading-data-from-multiple-db-to-another-server-using-ssis

I am facing issue in loading-data-from-multiple-db-to-another-server-using-ssis
I have referred the below link
Loading data from multiple db to another server using SSIS
SSIS Package FLow :
Unfortunately i am getting the error in "Execute SQL Task" as below:
[Execute SQL Task] Error: There is an invalid number of result
bindings returned for the ResultSetType: "ResultSetType_Rowset".
Appreciate if you could help me with the solutions.
Thanks
Based on the comments, to solve your issue
1. Evaluate your SQL Statement. For instance :
2. Once your variable query is evaluating, move to Execute SQL Task. It should look like this:
3. Next the resultSet should look like this (object_variable is of object type)
Why are we not using anything in parameter mapping ?
Answer: If we had a SQL query like Select col1, col2 from table1 where col3 = ?, Then we would be replacing ? with either a parameter or a variable.
In your case, delete everything inside parameter mapping.
Updated : Also, since you're query is Select * into tbl2 from tbl1, ResultSet property should be None instead of any other thing.
You have 2 Execute SQL Tasks
1, First Execute SQL Task, get list of tables and schema, it expects a Full Result set and map it to a object type variable.
2, Foreach loop container, ADO Enumerator, ADO source is the object type variable. Variable Mappings to 2 string type variables, 1 is for table name and 1 is for schema name.
Second Execute SQL Task, it has no Full Result set, no parameter mapping. Because table name/schema name changes are taken care of by Foreach loop container.

SSIS - SQL Command - Parameters

I edited the question based on the solution that Hadi gave.
I am using SSIS in VS 2013.
I have a user variable called MyVariableList and Query.
This is Expression in user variable Query: "SELECT cola, colB FROM myTable WHERE myID IN (" + #[User::MyVariableList] + ")"
I have a Script Task that set the value of #[User::MyVariableList].
Dts.Variables["User::MyVariableList"].Value = sList;
After that, I have A Data Flow Task with OLE DB Source (from 1 database) to another OLE DB Destination (another database on another server).
In the OLE DB Source Editor, I set
Data access mode: SQL Command from variable
Variable name: User:: Query
In the OLE DB Source connection, I have set the DelayValidation to True
Before I even can run the package, I am getting this error
How can I fix this issue ? Thank you
First of all, you are working with a project parameter not a project variable
You cannot achieve this using a parameterized sql command, you have to build the whole query inside a variable, and use it as source (SQL Command from variable)
Parameters are used to specify a single value, not concatenating the query string
Create a SSIS variable (User::Query), change the variable Evaluate As Expression property to True and write the expression in the variable Expression property. Like the following
"SELECT cola, colB FROM myTable WHERE myID IN (" + #[$Project::MyProjectVariable] + ")"
Note: to use a project parameter inside an expression use the following syntax : #[$Project::MyProjectVariable]

Running SQL Transport Schema Generation Wizard with datetime parameter in biztalk

I am trying to run the SQL Transport Schema Generation Wizard against a SQL 2012 server. The stored procedure has a datetime parameter. If i simply put in a date like 12/26/2013 05:00:00 Am, then the "Generate" button doesn't show an argument. If i try putting the date/time in a single quote or using a string like 2013-12-26T05:00:00.000, the parameter is generated, but i get the following error when i try to execute. "Failed to execute SQL Statement. Please ensure that the supplied syntax is correct. "
I got to this point by creating a SQL Query that output it's response using FOR XML AUTO, ELEMENTS in it. I then open my BizTalk solution in VS 2012, Go to "Add Items -> Add Generated Items". Select Add Adapter Metadata. From there, it asks the location of the message box. I use my local server. It then asks for the connection string for the SQL Server with the stored procedure. I enter that (it's the same as the server with the message box). I specify the namespace and the root element name for the document. This is set as a receive port. I next select stored procedure and move to the next screen. I then select the stored proc from a drop down list. Below, in a grid, i am shown the parameters for the stored proc. Here is where i am having trouble. I cannot seem to get it to accept the datetime argument no matter what i put in here.
Is there something i am doing wrong?
It is better to do the following steps and to use the new WCF-SQL rather than the old deprecated SQL adapter.
Add Items
Add Generated Items
Consume Adapter Service
Select sqlBinding and Configure the URI
Click Connect
Select Client (Outbound operations)
Select Strongly-Type Procedures
Select the Stored Procedure from Available categories and operations
Click Add
Give it a Filename Prefix
Click OK
This will generated the schemas plus binding files to create the port.
You also don't need to have the FOR XML AUTO, ELEMENTS in your stored procedure any more.

Execute sql task mapping variables in ssis

INSERT INTO [DEV_BI].dbo.[DimAktivitet]([Beskrivning],[företag],[Projektnummer],[Aktivitet],
loaddate)
SELECT NULL,
a.DATAAREAID,
a.PROJID,
a.MID_ACTIVITYNUMBER,
GETDATE()
FROM [?].dbo.[v_ProjCostTrans_ProjEmplTrans] a
LEFT OUTER JOIN [DEV_BI] .dbo.[DimAktivitet] b ON a.MID_ACTIVITYNUMBER = b.Aktivitet
AND a.DataAreaID = b.företag
AND a.ProjID = b.Projektnummer
WHERE b.Aktivitet_key IS NULL
I have this above sql code in execute sql task and in the parameter mapping i have mapped a variable named user::connectionstring with data type nvarchar , parameter name = 0. Im getting this following error.
[Execute SQL Task] Error: Executing the query "insert into [DEV_BI].dbo.[DimAktivitet]([Beskrivni..." failed with the following error: "Invalid object name '?.dbo.v_ProjCostTrans_ProjEmplTrans'.". Possible failure reasons: Problems with the query, "ResultSet" property not set correctly, parameters not set correctly, or connection not established correctly.
please someone help me to solve this.
It appears you are trying to change the database based on a variable. The Execute SQL Task can only use parameters as filters in the WHERE clause. This behavior is described in this TechNet article. For instance, you could do this:
insert into [DEV_BI].dbo.[DimAktivitet]([Beskrivning],[företag],[Projektnummer],[Aktivitet],loaddate)
select null,a.DATAAREAID,a.PROJID,a.MID_ACTIVITYNUMBER,GETDATE() from
[DEV_BI].dbo.[v_ProjCostTrans_ProjEmplTrans] a
left outer join
[DEV_BI] .dbo.[DimAktivitet] b
on a.MID_ACTIVITYNUMBER = b.Aktivitet AND a.DataAreaID = b.företag AND a.ProjID = b.Projektnummer
where b.Aktivitet_key is null
AND b.SomeFilterCriteria = ?;
If you really want to vary the database based on a variable, then you have three options:
Vary the Connection Manager connection string to your database connection based on an expression as described in a blog post. This is the best solution if you are only changing the database and nothing else.
Generate the entire SQL code as a variable and execute a variable as the SQL command instead of passing variables to the Execute SQL Command. This is described in this blog post under the section "Passing in the SQL Statement from a Variable".
Create a stored procedure, pass the parameter to the stored procedure, and let it generate the SQL it needs on the fly.

In SSIS how do I access the result of running an OLE DB Command?

I am using SSIS within Visual Studio 2010. My package looks like:
OLE DB Source -> Multicast -> 7 OLE DB Command's
The sixth of the above mentioned seven OLE DB Command's contains:
SELECT r.DeviceID
FROM hub.ResolveDeviceInstanceToDevice r
WHERE r.DeviceInstanceID = ?
AND r.DatasetID = ?
I wish to use the returned DeviceID in the seventh OLE DB Command. Can I do this? How? If not how should I do this?
I have put all 7 of the OLE DB Command beneath one Multicast, because several of them are using the same output from the OLE DB Source.
I am choosing not to use a stored procedure for this, because there is a preference to do this via ETLs. But if this is too complex, I'll consider moving to a stored procedure.
I know it's an old question, but I came across it doing a search for a similar problem. The Lookup is probably a better solution to the statement you gave like Kyle answered, but you can do what you are asking by adding a parameter to the SQL statement.
SELECT ?=r.DeviceID
FROM hub.ResolveDeviceInstanceToDevice r
WHERE r.DeviceInstanceID = ?
AND r.DatasetID = ?
So the first question mark will be param0 and will be the resulting column / field of the query.
You shouldn't be doing this with an OLE DB Command. Instead, you should use a Lookup task to achieve this.
Set your Lookup's connection to the database you're running the command against.
Set its query to
SELECT r.DeviceID, r.DeviceInstanceID, r.DataSetID
FROM hub.ResolveDeviceInstanceToDevice r
In the columns, join your source's DeviceInstanceID and DataSetID inputs to the appropriate lookup columns.
Add the DeviceID as an Output column.
Now you can use this value in another OLE DB Command.
I don't think it's possible with a select. Having a stored procedure, you could do
exec ? = GetDeviceId ?, ?

Resources