SSRS: how to use a parameter directly in the query? - ssrs-2012

Here's my query. In the application, the query is a little more complex but the focus is more on how to use the parameter
SELECT EmpName, Department, Salary
From tblEmployees
WHERE Salary >= #baseSalary
If a user want to select employees whose salaries start from a certain level they can do so.
I've found some videos on Plurasight on how to filter the result, but none on how to use the parameter directly in the query.
Thanks for helping

I create parameters in SSRS and then map them to the query with the Parameter tab in the Dataset Properties. If you use the same name for your parameter as the query, they will map automatically.
Here's an example of how I use them together:
Parameters
Dataset query
Parameter Tab of Dataset Properties

Related

How to create Interactive/Classic Report with dynamic SQL?

I'm running Apex 19.2 and I would like to create a classical or interactive report based on dynamic query.
The query I'm using is not known at design time. It depends on an page item value.
-- So I have a function that generates the SQL as follows
GetSQLQuery(:P1_MyItem);
This function may return something like
select Field1 from Table1
or
Select field1,field2 from Table1 inner join Table2 on ...
So it's not a sql query always with the same number of columns. It's completely variable.
I tried using PL/SQL function Body returning SQL Query but it seems like Apex needs to parse the query at design time.
Has anyone an idea how to solve that please ?
Cheers,
Thanks.
Enable the Use Generic Column Names option, as Koen said.
Then set Generic Column Count to the upper bound of the number of columns the query might return.
If you need dynamic column headers too, go to the region attributes and set Type (under Heading) to the appropriate value. PL/SQL Function Body is the most flexible and powerful option, but it's also the most work. Just make sure you return the correct number of headings as per the query.

How to add Multi-value Filter in cockpit spagobi?

select count(*)As CNT,Flat_status,property_name,Building
From xxacl_pn_flat_det_dm
where property_name in ($P{Property})
group by Flat_status,property_name,Building
$P{Property} returning multiple values in Dataset but not in cockpit view
As I understood, you want to pass multi value parameters to the dataset via some analytical driver from the cockpit interface. Well, first you must set the analytical driver to multivalue, then you can use the multivalue parameter syntax from spago, which is : $P{Property(';,;')} , this will give you something like:
select count(*)As CNT,Flat_status,property_name,Building
From xxacl_pn_flat_det_dm
where property_name in ('example1','example2')
group by Flat_status,property_name,Building

Filter out duplicate rows based on a subset of columns

I have some data that looks like this:
ID,DateTime,Category,SubCategory
X01,2014-02-13T12:36:14,Clothes,Tshirts
X01,2014-02-13T12:37:16,Clothes,Tshirts
X01,2014-02-13T12:38:33,Shoes,Running
X02,2014-02-13T12:39:23,Shoes,Running
X02,2014-02-13T12:40:42,Books,Fiction
X02,2014-02-13T12:41:04,Books,Fiction
what I would like to do is to only keep one instance of each datapoint in time like this (I don't care which instance in time):
ID,DateTime,Category,SubCategory
X01,2014-02-13T12:36:14,Clothes,Tshirts
X02,2014-02-13T12:39:23,Shoes,Running
X02,2014-02-13T12:40:42,Books,Fiction
Unfortunately, according to the Hive Language Manual, Hive's DISTINCT expression works on entire tables so doing something like this is not an option:
SELECT DISTINCT(ID, SubCategory),
DateTime,
Category
FROM sometable
How do I go about getting the second table above? Thanks in advance!
The usual approach for this kind of thing in SQL is a group by:
select ID, category, subcategory, min(datetime) datetime
from sometable
group by ID, category, subcategory

ORA-00979 not a Group By function error

Iam trying to select 2 values from a Table, Employee emp_name, emp_location grouping by emp_location, iam aware that the columns which are in group by function needs to be in select clause, but i would like to know whether is there any other way to get these value in a single query.
My intention is to select only one employee per location based on age.
sample query
select emp_name,emp_location
from Employee
where emp_age=25
group by emp_location
please help in this regard.
Thanks a lot for all the guys who have responded for this question. I will try to learn these windows functions as these are very handy.
The reason why this works in MySQL and not in Oracle, is because in Oracle, as well most other databases, you either need to specify a field (or expression) in the group by clause, or it has to be an aggregation which combines the values of all values in the group into a single one. For instance, this would work:
select max(emp_name),emp_location
from Employee
where emp_age=25
group by emp_location
However, it's may not the best solution. It will work if you want just the name, but you'll get into trouble when you want to have multiple fields for an employee. In that case max won't do the trick. In the query below, you might get a first name that doesn't match the last name.
select max(emp_firstname), max(emp_lastname), emp_location
from Employee
where emp_age=25
group by emp_location
On solution for this, is using a window function (analytical function). With those, you can generate a value for each record, without immediately reducing the number of records. For instance, with a windowed max function, you could select the max age for people named John, and display that value next to every John in the result, even if they don't have that age.
Some functions, like rank, dense_rank and row_number can be used to generate a number for each employee, which you can then use to filter by. In the example below, I created such a counter per location (partition by), and ordered by, in this case name and id. You can specify other fields as well, for instance if you want one name per age per location, you specify both age and location in partition by. If you want the oldest employee of each location, you can remove where emp_age=25 and order by emp_age desc instead.
select
*
from
(select
emp_name, emp_location,
dense_rank() over (partition by emp_location order by emp_name, emp_id) as emp_rank
from Employee
where emp_age=25)
where
emp_rank = 1
ORA-00979 not a Group By function error
Only aggregate functions and columns specified in the GROUP BY clause are allowed in the SELECT clause.
In that regard, Oracle follows the SQL standard closely. But, as you noticed in your comment, some other RDBMS are less strict than Oracle regarding that point. For example, to quote MySQL's documentation (emphasis mine):
MySQL extends the use of GROUP BY so that the select list can refer to nonaggregated columns not named in the GROUP BY clause. [...]
However, this is useful primarily when all values in each nonaggregated column not named in the GROUP BY are the same for each group. The server is free to choose any value from each group, so unless they are the same, the values chosen are indeterminate.
So, in the recommended use case, adding the extra columns to the GROUP BY clause will lead to the same result.
select emp_name,emp_location
-- ^^^^^^^^
-- this is *not* part of the ̀`GROUP BY` clause
from Employee
where emp_state=25
group by emp_location
Maybe are you looking for:
...
group by emp_location, emp_name
select emp_name,emp_location
from Employee
where emp_age=25
group by emp_name,emp_location
or
select max(emp_name) emp_name,emp_location
from Employee
where emp_age=25
group by emp_location

Can I use named parameters in BIRT queries?

I am writing queries for reports using Eclipse/BIRT. At the moment I create a query with ? characters for parameters, and I can then assign values to the parameters under the parameter tab.
However, if I need to assign the same value multiple times, I have to do this multiple times, once for each appropriate ?. Additionally, this system is fragile - if I add a question mark in the middle of the query, I need to adjust and reorder the list of parameters.
Is there a way to use named parameters rather than question marks in the original query?
BIRT query doesn't support named parameters but if database supports WITH statement, you can do what is illustrated here:
http://enterprisesmartapps.wordpress.com/2011/01/10/re-using-parameters-in-birt-data-set/
Basically, you're query becomes:
WITH
params AS
(SELECT ? AS year FROM dual)
SELECT * FROM tab1, params WHERE year = params.year
UNION
SELECT * FROM tab2, params WHERE year = params.year
Then you can set the ? once.

Resources