how to replace comma in List of string in Jasper report - jasper-reports

I have create one report with list of the string. The string got value parameter TO.REFOS_STATUS_CODE in ('10','ZZ','11','12','13'). i want to replace "," with ".". i have try the solution with my expression but it does'nt work.
The parameter expression is $P{refos_status}.equalsIgnoreCase("0") ?" ": " TO.REFOS_STATUS_CODE IN ( " +$P{refos_status}.replace( ',', '.' )+ ")".
Anyone know how to do that?
This is my query:
SELECT
TO.REFOS_STATUS_DESC_RPT ,
SUM(US.ENFUS_TOTAL_OFF_ACT) TOTAL
FROM TENF_RPT_UNSETTLE_SUMMACT US
INNER JOIN TREF_BRANCH B ON B.REFBR_BRANCH_ID = US.ENFUS_BRANCH
INNER JOIN TREF_STATE ST ON B.REFBR_STATE_CODE = ST.REFST_STATE_CODE
INNER JOIN TREF_OFFENCE_STATUS TO ON US.ENFUS_OFF_ACT =TO.REFOS_STATUS_CODE
WHERE
$P!{refos_status_1}
GROUP BY
TO.REFOS_STATUS_CODE,
TO.REFOS_STATUS_DESC_RPT
ORDER BY
TO.REFOS_STATUS_CODE,
TO.REFOS_STATUS_DESC_RPT

Related

Getting duplicate column ERROR while trying to insert same column with two different datatypes using SELECT INTO clause in PostgreSql

I need to insert createdate column twice with two different datatypes one with the datatype defined in the table itself and another in char datatype.
I can insert it by changing the alias name of createdate column but can't insert with same alias name which i need.
so help me out to get correct way of doing it.
My query:
SELECT DISTINCT TE.id, T.debatchqueuelink, TE.transactionlink,
EC.errorclassification, TE.errorvalue,
EC.errorparameter, TE.classificationlink, TE.description,
TE.createdate AS createdate, TO_CHAR(TE.createdate, 'MM/dd/yyyy') AS createdate,
TE.status, TE.rebutt, TE.rebuttedstatus, BQ.appbatchnumber,
BQ.scanbatchnumber, BQ.clientlink, BQ.locationlink, T.patientid,
(DEUD.firstname|| ' ' ||DEUD.lastname) AS deusername, DEUD.email AS deuseremail,
(QCUD.firstname|| ' ' ||QCUD.lastname) AS qcusername, TE.inactive,
TE.decomment
INTO table373
FROM qctransactionerror TE
INNER JOIN errorclassification EC ON EC.id = TE.classificationlink
INNER JOIN qctransaction T ON T.id = TE.transactionlink
INNER JOIN batchqueue BQ ON T.debatchqueuelink = BQ.id
INNER JOIN batchqueue QCBQ ON T.qcbatchqueuelink = QCBQ.id
INNER JOIN userdetail QCUD ON QCBQ.assignedto = QCUD.id
INNER JOIN userdetail DEUD ON BQ.assignedto = DEUD.id
WHERE TE.inactive='t'
AND TE.status IN ('ERROR','QCCORRECTED')
LIMIT 0
The actual error message I am getting is:
Duplicate column:column "createdate" specified more than once

How to add a single quote before each comma

a have a column as below
mystring
AC1853551,AC1854125,AC1855220,AC188115,AC1884120,AC1884390,AC1885102
I need to transformm it to get this output
mystring
('AC1853551','AC1854125','AC1855220','AC188115','AC1884120','AC1884390','AC1885102')
Here is my query that i tried
select CONCAT('( , CONCAT (mystring, ')')) from mytablename
I'm getting an error when it comes to insert a single quote '
Then i thought about replacing the comma with a ','
How to get desired output
i'm using postgres 10
A literal quote is coded as a doubled quote:
select '(''' || replace(mycolumn, ',', ''',''') || ''')'
from mytable
See live demo.

Print all values from column using custom predicate

How can I print next values
'aa, bb, cc, dd, ee'
from DB column, like that:
'aa-bb, aa-cc, aa-dd, aa-ee, etc'?
NOTE: If I have, for example following value: 'aa-bb', so 'bb-aa' should be skipped out
My TSQL Example doesn't work:
select l.SURNAME + '-' + l1.SURNAME
from LECTURERS l cross join LECTURERS l1
where l.CITY = 'Kyiv' and l.SURNAME <> l1.SURNAME and LEFT(l1.SURNAME,
charindex('-', l1.SURNAME)) <> l.SURNAME
Prints me following 'aa-bb, aa-cc, aa-dd, aa-ee', but how can I except 'aa-bb' <> 'bb-aa'

Conditionally replace select value from a mapping table

I want to replace a value, in a SELECT statement, if the value matches a value in a lookup table. This is to handle a mapping from a child to a parent.
DECLARE #Mappings TABLE
(
IdKey INT IDENTITY PRIMARY KEY ,
ParentModule NVARCHAR(255) ,
ChildModule NVARCHAR(255)
)
This is populated with child modules and their parent module, there will be about 200 such mappings.
Then in my SELECT statement I want to use the ParentModule instead of the Child but if the child is not matched then use whatever value would have been selected.
SELECT DISTINCT
RTRIM(StudentId) ,
ISNULL(( RTRIM(AOSCode) + '_' + RTRIM(AOSPeriod) ), '') AS Module
FROM Curriculum
The value I want to compare to ChildModule is (RTRIM(AOSCode) + '_' + RTRIM(AOSPeriod)). So if that matches I want the select to return the #Mappings ParentModule, otherwise the value returned by the concatenation of AOSCode_AOSPeriod
The SELECT is used in an INSERT INTO statement...
Try this:
SELECT DISTINCT
RTRIM(StudentId) ,
ISNULL(Map.ParentModule,ISNULL((RTRIM(AOSCode) + '_' + RTRIM(AOSPeriod)), '')) AS Module
FROM
Curriculum AS Cr
LEFT JOIN #Mappings AS Map ON
((RTRIM(Cr.AOSCode) + '_' + RTRIM(Cr.AOSPeriod)) = Map.ChildModule;
You will join Expression RTRIM(AOSCode) + '_' + RTRIM(AOSPeriod) with ChildModule. If there is a match you will show ParentModule. Otherwise you will show ISNULL(( RTRIM(AOSCode) + '_' + RTRIM(AOSPeriod) ), '').
Please take into account that I can not decide from your data if ISNULL have to be used in the expression in the join.

JPQL "DISTINCT" returns only one result

I am confused by DISTINCT in JPQL. I have two JPQL queries identical except for "DISTINCT" in one of them:
String getObjectsForFlow =
"SELECT " +
" se.componentID " +
"FROM " +
" StatisticsEvent se " +
"WHERE " +
" se.serverID IS NOT NULL " +
" AND se.flowID = :uuid " +
" AND se.componentID IS NOT NULL " +
"ORDER BY " +
" se.timeStamp desc ";
String getObjectsForFlowDistinct =
"SELECT DISTINCT " +
" se.componentID " +
"FROM " +
" StatisticsEvent se " +
"WHERE " +
" se.serverID IS NOT NULL " +
" AND se.flowID = :uuid " +
" AND se.componentID IS NOT NULL " +
"ORDER BY " +
" se.timeStamp desc ";
I run a little code to get the results from each query and dump them to stdout, and I get many rows with some duplicates for non-distinct, but for distinct I get only one row which is part of the non-distinct list.
NOT DISTINCT
::: 01e2e915-35c1-6cf0-9d0e-14109fdb7235
::: 01e2e915-35c1-6cf0-9d0e-14109fdb7235
::: 01e2e915-35d9-afe0-9d0e-14109fdb7235
::: 01e2e915-35d9-afe0-9d0e-14109fdb7235
::: 01e2e915-35bd-c370-9d0e-14109fdb7235
::: 01e2e915-35bd-c370-9d0e-14109fdb7235
::: 01e2e915-35aa-1460-9d0e-14109fdb7235
::: 01e2e915-35d1-2460-9d0e-14109fdb7235
::: 01e2e915-35e1-7810-9d0e-14109fdb7235
::: 01e2e915-35e1-7810-9d0e-14109fdb7235
::: 01e2e915-35d0-12f0-9d0e-14109fdb7235
::: 01e2e915-35b0-cb20-9d0e-14109fdb7235
::: 01e2e915-35a8-66b0-9d0e-14109fdb7235
::: 01e2e915-35a8-66b0-9d0e-14109fdb7235
::: 01e2e915-35e2-6270-9d0e-14109fdb7235
::: 01e2e915-357f-33d0-9d0e-14109fdb7235
DISTINCT
::: 01e2e915-35e2-6270-9d0e-14109fdb7235
Where are the other entries? I would expect a DISTINCT list containing eleven (I think) entries.
Double check equals() method on your StatisticsEvent entity class. Maybe those semantically different values returns same when equals() is called hence producing this behavior
The problem was the "ORDER BY se.timeStamp" clause. To fulfill the request, JPQL added the ORDER BY field to the SELECT DISTINCT clause.
This is like a border case in the interplay between JPQL and SQL. The JPQL syntax clearly applies the DISTINCT modifier only to se.componentID, but when translated into SQL the ORDER BY field gets inserted.
I am surprised that the ORDER BY field had to be selected at all. Some databases can return a data set ORDERed by a field not in the SELECTion. Oracle can do so. My underlying database is Derby -- could this be a limitation in Derby?
Oracle does not support SELECT DISTINCT with an order by unless the order by columns are in the SELECT. Not sure if any databases do. It will work in Oracle if the DISTINCT is not required (does not run because rows are unique), but if it needs to run you will get an error.
You will get, "ORA-01791: not a SELECTed expression"
If you are using EclipseLink this functionality is controlled by the DatabasPlatform method,
shouldSelectDistinctIncludeOrderBy()
You can extend your platform to return false if your database does not require this.
Still, I don't see how adding the TIMESTAMP will change the query results?
Both queries are incorrect JPQL queries, because ORDER BY clause refers to the item that is not on select list. JPA 2.0 specification contains example that matches to this case:
The following two queries are not legal because the orderby_item is
not reflected in the SELECT clause of the query.
SELECT p.product_name
FROM Order o JOIN o.lineItems l JOIN l.product p JOIN o.customer c
WHERE c.lastname = ‘Smith’ AND c.firstname = ‘John’
ORDER BY p.price
SELECT p.product_name
FROM Order o, IN(o.lineItems) l JOIN o.customer c
WHERE c.lastname = ‘Smith’ AND c.firstname = ‘John’
ORDER BY
o.quantity
Of course it would be nicer if if implementation could give clear error message instead of trying to guess what is expected result of incorrect query.