How we can pass multiple values in ODI scenarion variables - oracle-data-integrator

Is there any way to pass the multiple values in odi scenario Variable.
I am attaching the screenshot for the reference.

See the Oracle function listagg. For example:
SELECT
LISTAGG (
[col_value1] || ','
)
WITHIN GROUP (
ORDER BY [col_date] desc
) AS [col_alias]
FROM [table];
This would create list of values with comma in between. You could do a semicolon, comma, etc. You could place this in the Source Command feeding the Target Value, or just show it as immediate output in the Target Value.

Related

What is the correct syntax for Prepared Statement at Couchbase?

I'm trying to create Prepared Statement with named parameter at Couchbase 7.1 as follows:
PREPARE index_1 AS SELECT DISTINCT $column FROM bucket_name;
EXECUTE index_1 USING {'column': 'Name'};
I would like to receive the JSON array with distinct values for a given column name which is achievable using SQL syntax e.g.: SELECT DISTINCT Name FROM bucket_name;
Instead of this, I receive only given column name.
How to do it correctly?
Named parameters or positional parameters can be used for values only.
Not for field names or identifiers.
Above statements and results are correct.
If you must use the following if you want distinct Name field values.
PREPARE index_1 AS SELECT DISTINCT Name FROM bucket_name;
EXECUTE index_1;
OR
PREPARE p1 AS SELECT DISTINCT RAW t.[$column] FROM bucket_name AS t;
EXECUTE p1 USING {'column': 'Name'};
see N1QL query to select a dynamic key in Couchbae explanation of dynamic fields

How to pass a parameter in a SQL query in MS SQL Server from an Excel sheet

Let's say I have this query in SQL Server:
select *
from Table1
where Column1 IN ('01061120192T')
I want to pass the values for Column1 from a column in an Excel sheet.
I'm able to pass a single value to the query as mentioned here. But parenthesis of IN can accept multiple values so I want to pass 1000 values in the parenthesis from a column in an Excel sheet.
Tried to pass multiple values to the parameter as below, but that's not working.
=Sheet1!$G$1:$G$5
You pass variables in SSIS as a ?, and then define your variables in your parameter mapping pane.
select *
from Table1
where Column1 = ?
Then, you need to go to your Parameter mapping pane and click Add. Select your variable's name in the Variable name Column. Then Input as the direction. Leave Paramter Size as -1.

parsing nvarchar(max) data field in sql

I have a field with stings like 'marketplace-used-new-ebook-rental_new-rental_used' where 'rental_new' is one piece and so on. This is all of the possible elements in the sting but they can be in any order and contain one or more pieces. How do I break this up so I can account for all the different combinations? I also cannot create functions on this database.
you have three options really
Do the work at the application layer
Write a cursor to do it
Use XML to do it
the below example is for XML
Note: XML can only be used if you can guarantee that your input string does not contain any XML characters. One string with <, > or & and the query will fail.
SELECT distinct a.split_me
FROM
(
SELECT cast('<X>'+replace('marketplace-used-new-ebook-rental_new-
rental_used','-','</X><X>')+'</X>' as XML) as xml_convert
)xml_data
CROSS APPLY
(
SELECT fdata.D.value('.','nvarchar(50)') as split_me
FROM xml_data.xml_convert.nodes('X') as fdata(D)
) a
SQL server 2016 has a built in function to break out data, but until then it is one of those three options.

How can I extract multiple values from an XML column, using a function similar to value()?

I'm trying to extract xml metadata from from SQL Server's Report Server Database. My current query is listed below:
SELECT
a.Name as 'ReportName'
,a.ReportXML
,Parameter = x.value('(Parameter/Name)[1]','VARCHAR(250)')
FROM (SELECT C.Name,c.itemID,CONVERT(XML,CONVERT(VARCHAR(MAX),C.Parameter)) AS reportXML
FROM ReportServer.dbo.Catalog C
WHERE C.Content is not null
and c.Type = 2 -- Report only
) a
cross apply reportXML.nodes('/Parameters') r (x)
WHERE 1=1
and name ='ReportName'
My objective is to return all parameters associated with a report. The x.value method will only return 1 value at most. (It currently returns the first parameter of the report because 1 is hard coded in the string literal.) I know there are 5 parameters for the report I'm looking at.
Is there another function with similar syntax that will allow me to return all the values? Or is there a wildcard that I can use in place of the number? I've tried multiple functions on msdn with no luck.
Your query is using nodes('/Parameters'). This will return a resultset with one row for each Parameters element - but there is only one probably.
With Parameter = x.value('(Parameter/Name)[1]','VARCHAR(250)') you are reading the first name of the first Parameter. If there are more Parameter elements nested within Parameters you will read only the first...
Without an example of your actual XML it is not easy to answer but:
Try to add one nesting level by adding this below your cross apply
outer apply r.x.nodes('Parameter') AS p (y)
Then change the column to
,Parameter = y.value('Name[1]','VARCHAR(250)')
This should read the first Name element of each Parameter element
If you need further help, please poste an example of your XML.
Btw: I do not understand this:
CONVERT(XML,CONVERT(VARCHAR(MAX),C.Parameter)
What is the initial type of C.Parameter, that you have to cast it to VARCHAR(MAX) and then to XML? If you are still using the deprecated TEXT, NTEXT or IMAGE you should consider to change this!

Assigning a SQL NULL to a SSIS string - A SSIS Flaw?

I fetch a result set with an execute SQL task. It has only one column NullTime varchar. It has three rows, first one is NULL. I want to simply iterate and display the value of these rows. If I do it only by C# script, then there is no problem. The NULL is displayed as a blank. The same thing can also be done with a foreach loop.
How to do it with foreach - use that loop to read each row and set the value of each row to SSIS string User::STR_WORD. Then, simply display User::STR_WORD with a C# script task.
In the pure C# method, I can even assign the blank value (actually a NULL) to the SSIS string. But with foreach loop method, I get an error because of the NULL value.
The error is -
Error: The type of the value being assigned to variable "User::STR_WORD" differs from the current variable type. Variables may not change type during execution. Variable types are strict, except for variables of type Object.
How do I fix this error ? Is script the only alternative to what seems to be a flawed for
loop ?
A workaround for this is the Coalesce function which will convert NULLs to the value you specify.
SELECT
COALESCE([YourColumn], 'EnterValueHere') AS [YourColumn]
FROM YourTable
So, this will replace a null with the value you want to use instead. It will
prevent the weird FOR loop from suddenly crashing.
Create a temporary table to see this working -
create table ##tester
(names varchar(25))
insert into ##tester
values(Null)
insert into ##tester
values('Not a null value')
select names from ##tester
select coalesce(names, 'Null has been obliterated!') from ##tester

Resources