filter tablix without datasource values in ssrs - visual-studio

I have SSRS report and I need to filter a static table that I created inside the report based on parameter. There is no data source to this table and I'm entering the data manually.
The tablix contain 3 columns.
How can I filter the columns based on parameter?
I tried in the expression =#param1 for example but it doesn't work.
For now I only manage to filter if the expression is on data source fields.

Do you literally have a table with a number of values in it written directly into the report? If so I don't think you will be able to perform any filtering on it as effectively all you've done it write data into textboxes that are displayed.
I would imagine your best option would be to instead create a new dataset and populate this with your static data, e.g.
SELECT 'A' AS Letter, 'English' AS Language
UNION
SELECT 'B' AS Letter, 'French' AS Language
UNION
SELECT 'A' AS Letter, 'German' AS Language
To give you a table as follows
Letter | Language
-------+----------
A | English
B | French
A | German
That you could then filter on Letter = A

So essentially you have a Tablix that has 3 columns pre-populated with information you have manually entered into the text boxes themselves? Since you've already entered that data, I don't believe there is a way to filter that at run time. That data is hard coded in essence. The Filter ability in SSRS is used as a WHERE clause so it restricts what is brought forth into the report from the query.
I would create a data source connection to a dummy database, create a DataSet, and create a query that fills a temporary table will all the information that you've manually entered. Once you create the temporary table and inserted values into it, you can then perform a SELECT with a parameter. Your Tablix will only be populated with information that matches the parameter. Something to the effect of this:
CREATE TABLE #TempTable (
ID INT
,Name VARCHAR(MAX)
,Email VARCHAR(MAX)
)
INSERT INTO #TempTable (
ID
,Name
,Email
)
VALUES (
1
,'Bob'
,'bob#email.com'
)
,(
2
,'Frank'
,'frank#email.com'
)
,(
3
,'Jim'
,'jim#email.com'
)
SELECT
*
FROM
#TempTable
WHERE
ID = #ID
DROP TABLE #TempTable

Related

How do you Save calculated columns from one table to another table using Oracle APEX?

As the question states, I'm trying to save calculated data, that is the result of a select statement, to another table. In this Image, the column with green outline is a database column and the columns with red outline are calculated based on that column, I want to save the Red outlined columns to another table where the column names would be same.
This looks like a classic report. Is it? If so, it is result of a select statement. As it calculates all values you're interested in, you'd use it in an insert statement. For example, you could create a button and create a process that fires when that button is pressed. It would then
insert into target_table (emp_id, salary, house_rent, ...)
select emp_id, ... whatever you select in report's query
from ...
However: data changes. What will you do when something - that is used to calculate those values - is changed? Will you delete those rows and insert new ones? Update existing values? Add yet another row?
If you'd update existing values, consider using merge as it is capable of inserting rows (in when not matched clause, in your case) , as well as updating rows (in when matched). That would look like this:
merge into target_table t
using (select emp_id, ... whatever you select in report's query
from ...
) x
on (t.emp_id = x.emp_id)
when matched then update set
t.salary = x.salary,
t.house_rent = x.house_rent,
...
when not matched then insert (emp_id, salary, house_rent, ...)
values (x.emp_id, x.salary, x.house_rent, ...);
You can use the INSERT INTO SELECT statement - plenty of examples available on google
INSERT INTO another_table (
emp_id,
col1,
col2
)
SELECT emp_id,
calculated_col1,
calculated_col2
FROM first_table

How to create and use a multi-select list in APEX ORACLE?

I have a table called Employees with Employee_id and Employee_Name columns. Now i want to create a page with Checkbox in-front of every Employee Name, select the ones that are needed, store them into a temporary table and use them for further operations. The problem i am facing is to how to create that multi select list and store the select values in thee table. Is there an Item for multi select? If not, how should i do it?
There's the Shuttle item. On the left side, you'd display list of all employees. Item buttons allow you to move all (or only some of them) to the right side of the item. Once you submit the page, list of employee IDs is stored into a table column in a form of colon-separated values, for example
6547:8879:5587:9987
This is a simple way of doing that. However, once you have to actually do something with those values, you have to split them to rows. Not a problem, though. Here's a query:
SQL> with emps (shuttle_item) as
2 (select '6547:8879:5587:9987' from dual)
3 select regexp_substr(shuttle_item, '[^:]+', 1, level) one_item
4 from emps
5 connect by level <= regexp_count(shuttle_item, ':') + 1;
ONE_ITEM
---------------------------------------------------------------------
6547
8879
5587
9987
SQL>
Or, you could create a tabular form which also displays all employees and has checkboxes at the beginning of every line. You'd then create a process which - in a loop - stores selected values into a temporary table you mentioned. For example:
-- F01 = row selector. If you check 1st and 3rd row, f01.count = 2 (2 rows checked)
-- f01(1) = 1 (row #1), f01(2) = 3 (row #3)
-- F02 = EMP_ID. f02(1) = EMP_ID that belongs to employee in 1st row,
-- f02(3) = EMP_ID that belongs to emplyee in 3rd row
declare
l_id number;
begin
for j in 1 .. apex_application.g_f01.count
loop
l_id := apex_application.g_f02(apex_application.g_f01(j));
insert into temp_table (emp_id) values (l_id);
end loop;
end;
There is an option for creating multi select list in oracle apex 5.1.
Create a pageItem of type: 'select list'.
Make the 'Allow multi
selection' to 'Yes'.
Write the SQL query for your select list under
the 'List of Values' attribute.
Then the select list will be
displayed based on our query.
Query format is:
select [displayValue],
[returnValue]
from ...
where ...
order by ...
Now once you select multiple value from select list(using ctrl+click), these are stored as ':' separated values in the select list page item.
I've created a video some times ago that covers your problem. It's a step by step tutorial how to create checkboxes and process them.
Video is available here:
https://www.youtube.com/watch?v=T-LXRMWQbPk
Regards
If the list is too big, I recommend to use the Popup LOV item with the Multiple Values switch activated instead the Select list or the Shuttle, because it has an internal search field for the objects list, doing way easier for the user to find the target values. Also, just as the Select List or Shuttle item, you can set a Separator character for the selected fields.

prevent sqldeveloper from expanding asterisc wildcard in view

I have two views, the second one depends on the data from the first and adds some columns from a different table.
In sql developer I define the views as follows:
view1:
select col11, col12, col13, col14, col15, col15, col16, col17
from table1
view2:
select view1.*, col22, col23
from view1 join table2 on view1.col11 = table2.col21
But when after saving, sqldeveloper expands the "view1.*" part of the second view to the explicit list of columns, so view2 ends up being rewritten as:
select view1.col11, view1.col12, view1.col13, view1.col14, view1.col15, view1.col15, view1.col16, view1.col17, col22, col23
from view1 join table2 on view1.col11 = table2.col21
which is harder to read and to mantain.
Is there a way to prevent this behavior?
Thanks
That's not SQL Developer doing that, it's the database.
You can create the view using the * syntax, but the database will always translate that to a fully qualified SELECT list.
CREATE VIEW LOCS
AS select * from locations;
Now ask the DB for the DDL, and you get
CREATE OR REPLACE FORCE EDITIONABLE VIEW "HR"."LOCS" (
"LOCATION_ID",
"STREET_ADDRESS",
"POSTAL_CODE",
"CITY",
"STATE_PROVINCE",
"COUNTRY_ID"
) AS
SELECT
"LOCATION_ID",
"STREET_ADDRESS",
"POSTAL_CODE",
"CITY",
"STATE_PROVINCE",
"COUNTRY_ID"
FROM
locations;
The view is defined at run-time, it'll take the existing column list and assume you want the same column names in your view as you want in the underlying objects where those columns are being pulled from.
From the Docs -
Expansion of Defining Queries at View Creation Time When a view is
created, Oracle Database expands any wildcard (*) in a top-level view
query into a column list. The resulting query is stored in the data
dictionary; any subqueries are left intact. The column names in an
expanded column list are enclosed in quote marks to account for the
possibility that the columns of the base object were originally
entered with quotes and require them for the query to be syntactically
correct.

How to use a query result or column value to define a select column name?

How can I use a column value as a column name. I've tried this:
SELECT TableX.(
SELECT OdTable.columnamecell
from OdTable
where 1 =1
AND OdTable.KeyValue = TableX.SomeValue
) as MyValue
,TableX.OtherValue as OtherValue
, TableX.SomeValue
from TableX
WHERE 1 = 1
Or to say it another way: Can I use a table column value as a column name for another query or sub-query?
To clarify: The table: OdTable has a column with values that are the column name in another table.
No, and Yes. You can't do this with "standard" SQL; all table and column names must be known, as literals, when the query is compiled; they can't be provided at runtime. What you want is called "dynamic SQL"; sometimes it is the only solution to a problem, but most of the time it is used when it is not necessary. It has several disadvantages (security risk, performance penalty, difficulty to maintain, ...)

how to pass parameter to oracle update statement from csv file and excluding null values from csv

I have a situation where I have following csv file(say file.csv) with following data:
AcctId,Name,OpenBal,closingbal
1,abc,1000,
2,,0,
3,xyz,,
4,,,
how can I loop through this file using unix shell and say for example for column $2 (Name) , I want to get all occurances of Name column accept null values and pass it to for example following oracle query with single quotes '','' format?
select * from account
where name in (collection of values from csv file column name
but excluding null values)
and openbal in
and same thing for column 3 (collection of values from csv file column Openbal
but excluding null values)
and same thing for column 4 (collection of values from csv file column
closingbal but excluding null values)
In short what I want is pass the csv column values as input parameter to oracle sql query and update query too ? but again I dont want to include null values in it. If a column is entirely null for all rows I want to exclude it too?
Not sure why you'd want to loop through this file in a unix shell script: perhaps because you can't think of any better approach? Anyway, I'm going to skip that and offer a pure Oracle solution.
We can expose data in CSV files to the database using external tables. These are like regular tables except their data comes from files in OS directories on the database server (rather than the database's storage). Find out more.
Given this approach it is easy to write the query you want. I suggest using sub-query factoring to select from the external table once.
with cte as ( select name, openbal, closingbal
from your_external_tab )
select *
from account a
where a.name in ( select cte.name from cte )
and a.openbal in ( select cte.openbal from cte )
and a.closingbal in ( select cte.closingbal from cte )
The behaviour of the IN clause is to exclude NULL from consideration.
Incidentally, that will return a different (larger) result set from this:
select a.*
from account a
, your_external_table e
where a.name = e.name
and a.openbal= e.openbal
and a.closingbal = e.closingbal

Resources