Traverse Ireport Input control paramter of type collection(mutiselect parameter) - jasper-reports

I have a Oracle query where I want to check content of a Ireport input control parameter of data type "collection" like below the SQL
select devlocview.floorname FROM AlarmDeviceView alrmDevView INNER JOIN devicelocationview devLocView ON devlocview.oid=alrmdevview.deviceoid
LEFT OUTER JOIN DEVICEGROUPVIEW devGrpView ON devlocview.oid=devgrpview.deviceoid
LEFT OUTER JOIN RackCapacityView rackCapView ON devlocview.RACKID=rackCapView.oid WHERE
(
( $P{building.name} IS NOT NULL AND devlocview.buildingname = $P{building.name} )
OR
( $P{building.name}='All Buildings' AND devlocview.buildingname IN (SELECT buildingname FROM cdmr.devicelocationview ) )
)
AND $X{IN, devlocview.floorname, floor.name}
Here
"floor.name" is the multiselect(collection type) inputcontrol parameter of Ireport which contains the value selected by the user in UI
"devlocview.floorname" SQL query output
Now I want to do something like
IF USER SELECTS "ALL BUILDING" IN UI i.e. IF floor.name contains "ALL BUILDING"
THEN DO SOMETHING
ELSE
THEN DO SOMETHING
The problem I am facing is I am not able to traverse and check the contents of Ireport Input control parameter "floor.name" which is of type "collection"

Related

Fetch rows from postgres table which contains a specific id in jsonb[] column

I have a details table with adeet column defined as jsonb[]
a sample value stored in adeet column is as below image
Sample data stored in DB :
I want to return the rows which satisfies id=26088 i.e row 1 and 3
I have tried array operations and json operations but it does'nt work as required. Any pointers
Obviously the type of the column adeet is not of type JSON/JSONB, but maybe VARCHAR and we should fix the format so as to convert into a JSONB type. I used replace() and r/ltrim() funcitons for this conversion, and preferred to derive an array in order to use jsonb_array_elements() function :
WITH t(jobid,adeet) AS
(
SELECT jobid, replace(replace(replace(adeet,'\',''),'"{','{'),'}"','}')
FROM tab
), t2 AS
(
SELECT jobid, ('['||rtrim(ltrim(adeet,'{'), '}')||']')::jsonb as adeet
FROM t
)
SELECT t.*
FROM t2 t
CROSS JOIN jsonb_array_elements(adeet) j
WHERE (j.value ->> 'id')::int = 26088
Demo
You want to combine JSONB's <# operator with the generic-array ANY construct.
select * from foobar where '{"id":26088}' <# ANY (adeet);

Parameter in custom SQL query taking forever in Computing view layout

I have a custom sql query from oracle DB using live connection. Following query returns the results in less than a second. When I pull the columns in the Tableau sheet, I get the layout quickly.
SELECT COLUMN_A,
FROM TABLE_A ss, TABLE_B sc, TABLE_C pse, TABLE_D ps
WHERE ss.hnspartnerid = sc.swcustomerid
and sc.COMPANY = 'AND'
and ss.SITE = pse.SRCSITE
and pse.SITE = ps.SITE
AND ss.ACTTYPE <> 'Physical Location'
When I replace the value with the parameter to create the dynamic query, "Compute layout" is taking forever. I get the results in less than a second on the "Data Source" tab.
SELECT COLUMN_A, FROM TABLE_A ss, TABLE_B sc, TABLE_C pse, TABLE_D
ps WHERE ss.hnspartnerid = sc.swcustomerid and sc.COMPANY =<Parameters.CustomerID> and ss.SITE = pse.SRCSITE and pse.SITE =
ps.SITE AND ss.ACTTYPE <> 'Physical Location'
Can anyone guide me on what I am doing wrong? I believe Tableau executes the query after the user inputs the parameter. Is it executing the query before that and using parameter as a filter?

SSRS - Refine WHERE Criteria in T-SQL Query

I am developing a report that should return results depending on user-specified parameters. There are 3 report parameters, one is a drop down with 'Locations', and the other two are text parameters to search within 'user_id' and users' first or last name. This is what I am currently using:
SELECT *
FROM UserTable1
WHERE Location = #Location
AND (user_id LIKE '%'+#SearchUserID+'%'
AND first_name LIKE '%'+#SearchUserName+'%'
OR last_name LIKE '%'+#SearchUserName+'%')
If the #SearchUserID parameter field is left blank by the user, all user_ids should be returned (that meet the other 2 parameters). If specified, it will return user_ids that have that substring in the user_id. Same thing goes for the #SearchUserName parameter field. If left blank, it should return all users that meet the other parameters. If specified, it should return all users that have that substring in their first_name or last_name (but only results that meet the other parameters). If both are left blank, it should return all users.
The query I have above is not working. It seems to just return results meeting the #SearchUserName parameter, but disregards the #SearchUserID parameter. Is there a way to fix this? I had put the #SearchUserID filter on the tablix itself, using the expression:
="" & Parameters!SearchUserID.Value & ""
But this has resulted in severely hampered performance..
Try this. You must pass NULL if parameter is blank(empty).
SELECT *
FROM UserTable1
WHERE Location = #Location
AND (user_id LIKE '%'+#SearchUserID+'%'
OR #SearchUserID IS NULL
)
AND (first_name LIKE '%'+#SearchUserName+'%'
OR last_name LIKE '%'+#SearchUserName+'%'
OR #SearchUserName IS NULL
)
"....but disregards the #SearchUserID parameter." What data type of user_id?

Null when using Jasper report list component?

When select field and adding it to list component in jasper report it can't display values from database it return null
Query for it data set
SELECT TRAFFIC."DESC", INC.UNBILLED_AMOUNT FROM INC_CONTRACT_USAGE INC
INNER JOIN TRAFFIC_SERVICE TRAFFIC ON TRAFFIC.TRAFFIC_SERVICE_ID = INC.TRAFFIC_SERVICE_ID
WHERE INC.TRAFFIC_SERVICE_ID IN (1,2,3)

How do I count the number of objects in SQL Server 2000 and get its modified date?

I need to count the number of objects in SQL Server 2000 when restoring from the database to make sure that restore includes the latest updates. I also wanted to get the latest date an object was created or modified.
Specifically wanted to get counts for number of tables, the number of views, the number of udfs, the number of sprocs, and the date it was created or modified.
select
count(xtype) as [MyCounts],
crdate as [CreateDate],
refdate as [ModifiedDate]
from sysobjects
where xtype like 'U%'
--does not appear to be working correctly.
A very basic solution would simply use grouping and aggregating, like this:
SELECT
xtype,
total_count = COUNT(*),
last_crdate = MAX(crdate),
last_refdate = MAX(refdate)
FROM sysobjects
GROUP BY xtype
This, however, returns information on all types of objects in the current database, including those you didn't mention in your question, like constraints, keys etc.
So you might want to narrow the resulting list by applying a filter on xtype, like this:
SELECT
xtype,
total_count = COUNT(*),
last_crdate = MAX(crdate),
last_refdate = MAX(refdate)
FROM sysobjects
WHERE xtype IN ('U', 'V', 'FN', 'TF', 'IF', 'P')
GROUP BY xtype
Note that there are three types of UDFs in SQL Server. They are designated in sysobjects as follows:
FN – scalar function
TF – multi-statement table-valued function
IF – inline table-valued function
Accordingly the information about functions will be scattered in three rows if you use the above script. If you'd like to group those results in one row, your query would have to be slightly more sophisticated. For example, like this:
SELECT
type,
total_count = COUNT(*),
last_crdate = MAX(crdate),
last_refdate = MAX(refdate)
FROM (
SELECT
type = CASE
WHEN xtype = 'U' THEN 'table'
WHEN xtype = 'V' THEN 'view'
WHEN xtype = 'P' THEN 'proc'
WHEN xtype IN ('FN', 'TF', 'IF') THEN 'udf'
END,
crdate,
refdate
FROM sysobjects
WHERE xtype IN ('FN', 'TF', 'IF', 'P', 'U', 'V')
) s
GROUP BY type
Here the original types are first replaced by custom types based on the xtype value. All rows pertaining to functions are marked simply as udf, regardless of the actual function type, so in the end you can simply group by the custom type column and get the necessary totals, the information on functions now being gathered in one row.
Reference:
sys.sysobjects (Transact-SQL)
You should post the errors that you're getting so it's easier to diagnose. However, looking at your query, it's likely because you're missing a GROUP BY to accompany the COUNT aggregation you're attempting to do.
Now, the real question is how do you display a COUNT aggregation along with line-specific information like the created date?
If there are 5 views and 4 procs, what does each line look like? What are the column headers? Is the COUNT shown on each row along with the detail for that item, like this?
select
c.cnt as [MyCounts],
s.name as [Name],
s.xtype as [Type],
s.crdate as [CreateDate],
s.refdate as [ModifiedDate]
from
sysobjects s
inner join (select COUNT(1) cnt, xtype from sysobjects group by xtype) c
on s.xtype = c.xtype
where
s.xtype like 'U%'