Denodo: SPLIT and FLATTEN in the same query statement - denodo

regarding to the FLATTEN documentation you have to create a view containing a split first, before you can use FLATTEN.
https://community.denodo.com/docs/html/browse/7.0/vdp/vql/queries_select_statement/from_clause/flatten_view_flattening_data_structures
In my case I have to query with both steps within the same statement.
Documentation:
viewA = SELECT test1, split(test2, ‘;’) AS test2 FROM source
viewB = SELECT * FROM FLATTEN viewA AS V (v.test2)
I need to do something like:
SELECT * FROM FLATTEN (SELECT test1, split(test2, ‘;’) AS test2 FROM source) AS V (v.test2)
Would that be possible?

Try with a common-table expression:
WITH common_table_expression_1
AS (
SELECT test1, split(test2, ';') AS test2
FROM source
)
SELECT *
FROM FLATTEN cte1 AS v(v.test2);

Related

Select if multiple variables missing

How would I find the id of a person in my table who has SYSMIS for all the variables A,B,C & D? A to D are sequential variables.
I can't do a select if because it doesn't accept the to in:
select if (A to D) = SYSMIS.
This will do it:
select if nmiss(A to D)=4.
If the variables weren't sequential you could use
select if nmiss(A, B, C, D)=4.

How to filter a SSRS report based on 2 datasources

I have created a stored proc where I have data coming from 2 data sources. I have created a Union between source A and source B and then feeding this as a dataset to the SSRS report.
Now the user wants to see the report based on a source parameter which will give them the ability to select/filter the report based on the data sources either "source A", "source B" or "both". So if user selects source A , then report should show data from source A only and if "both" then it will show results from both source A and source B.
One way , I am trying to tackle this problem is creating 3 separate data sets and then using a parameter. I am not sure if that's the best design approach. Please share if anyone has any better ideas.
Thanks in Advance !
You could simply tag an extra column onto your query with the source identified something like
SELECT *, 'A' as Src FROM myFirstDataSource
UNION
SELECT *, 'B' as Src FROM mySecondDataSource
Then just apply a filter on the Src column.
Alternatively just do this in the SP itself by passing a parameter in from the report to determine what data to fetch, something like.
CREATE PROC myProc (#myParam varchar(1) = '') AS
DECLARE #t TABLE (Src varchar(1), ColumnA varchar(10), ColumnB int, ColumnC int)
IF (#myParam = '' OR #myParam = 'A')
BEGIN -- get data from first datasource
INSERT INTO #t
SELECT 'A', someCOlumnA, SomeColumnB, SomeColumnC FROM myFirstDataSource
END
IF (#myParam = '' OR #myParam = 'B')
BEGIN -- get data from second datasource
INSERT INTO #t
SELECT 'B', someCOlumnA, SomeColumnB, SomeColumnC FROM mySecondDataSource
END
SELECT * FROM #t
You don't really need the Src column in the second option but it might be useful in case you want to highlight where data comes from in the report.

Run 2 select statement in DB2 depending of the result of one of them

I'm trying to do an SP in DB2 with 2 select statements. If the first select returns null, perform the second one.
For example
Select a, b, c from table A where...
--If first select returns null
Select a, from table B where...
I tried a lot of ideas but none of them worked.
Thanks
You can use this general pattern, of course you will have to adapt your two result sets to match
WITH first AS
(
SELECT ..result1.. FROM table1
WHERE ..clause1..
)
SELECT ..result1.. FROM first
UNION
SELECT ..result2.. FROM table2
WHERE 0=(SELECT COUNT(1) FROM first)
AND
..clause2..
Here is a simple way to write that
Select a, from table B where...
and not exists (select * from table a where...)
union
select a,.. from table A)

How do I get one output stream for several statements in Esper?

I'm new to Esper and I'm trying to get the results of multiple EPStatements to run through the same UpdateListener. For instance:
EPServiceProvider epService = EPServiceProviderManager.getDefaultProvider();
EPStatement avgStatement = epService.getEPAdministrator()
.createEPL("select avg(price) from OrderEvent.win:time(30 sec)");
EPStatement sumStatement = epService.getEPAdministrator()
.createEPL("select sum(price) from OrderEvent.win:time(60 sec)");
Is it possible to combine the results of both of those EPStatements into a separate statement? Something like:
EPStatement bothStatements = epService.getEPAdministrator()
.createEPL("select * from avg(price), sum(price) where a.id=b.id");
bothStatements.addListener(listener);
I tried using inserting both statements into an Esper Named Window, but it seems like I can't do something like this where:
Event = (id, itemName, price)
Statement1 = (id, avg)
Statement2 = (id, sum)
Named Window = (id, avg, sum)
I would like to be able to combine the results of multiple statements and get a set of results (per event) into a single output stream.
Thanks for helping.
Did you consider that the same listener can be attached to two statements. What I means is "avgStatement.addListener(myListener)" and "sumStatement.addListener(myListener)".
As an alternative you can use insert-into to populate the same stream. The would be like "insert into MyStream select avg(price) as avgPrice, 0 as sumPrice from ..." and "insert into MyStream select 0 as avgprice, sum(price) as sumPrice from ...".
There is also the concept of a variant stream like variant types in visual basic. This lets you insert anything into a stream that is variant stream because variant streams don't need to be strongly typed.

temp table creation in informix 4GL SE

How should I create and populate data in a temp table? then how can I print data retrieved on temp table? I saw example like this; but no further help. SO I need some help.
SELECT DISTINCT * FROM Table INTO TEMP Temp1;
You select the data just like you would from any other table:
SELECT * INTO r_temp1.* FROM Temp1
or defining cursors for such a statement, and using a FOREACH loop, or ...
The trick is that you need to know at compile time what the columns in Temp1 are going to be. In this case, you could use:
DEFINE r_temp1 RECORD LIKE Table.*
In more general cases, you'll probably assemble a record by hand from the relevant bits and pieces:
DEFINE r_temp1 RECORD
col1 LIKE Table1.ColumnA,
col2 LIKE Table2.ColumnB,
...
colN LIKE TableZ.ColumnZ
END RECORD
I created the following function that can be called passing in the temp-table name:
function unload_temp(l_table)
define
l_table char(20),
l_file char(20),
str char(512)
let l_file = l_table clipped, ".out"
let str = "select * from ",l_table clipped
whenever error continue
prepare stmt_table_exists from str
whenever error stop
#Return if table does not exist
if sqlca.sqlcode = -206
then
return
end if
unload to l_file delimiter "|" str
end function #unload_temp()
This will create a file called tableName.out.
This is extremely helpful when debugging and you want to see how a temp table looks in middle running a program.

Resources