How can I merge multiple row data into one single row in COGNOS 10 - merge

I'm trying to merge multiple rows into one for example I have one DIIN but the data could appear in one of four columns as per the picture. My aim is to try and have one row with the relevant information displaying in the one line.
My skills on COGNOS are limited so any reply description/pictures would need to be in billy basics form like a step by step guide or a link to any videos would be a bonus.
Thank you in advance.

If only one of the columns will have the "data", you can use the MAXIMUM detail aggregation for each of those columns.
Your graphic appears to show a bunch columns not relevant to the question. I assume what really matters is...
DIIN
External Due In
Internal Due Out
Internal Due In
External Due Out
00419710301
Due Qty 3 OU-Other Unit Committed Stock
00419710301
Due Qty 3 IU-AinU Exchange
...which would be represented in SQL in a format useful for those who would provide an an answer. It's helpful to use a tool like https://dbfiddle.uk/ for this.
In future, please consider entering data as text or SQL statements so that potential helpers don't have to do the heavy lifting for you.
In SQL terms (much easier to type than Cognos GUI elements), I think the solution have is...
SELECT DISTINCT DIIN
, [External Due In]
, [Internal Due Out]
, [Internal Due In]
, [External Due Out]
FROM TableName
...and the solution you are looking for is...
SELECT DIIN
, MAX([External Due In]) AS 'External Due In'
, MAX([Internal Due Out]) AS 'Internal Due Out'
, MAX([Internal Due In]) AS 'Internal Due In'
, MAX([External Due Out]) AS 'External Due Out'
FROM TableName
GROUP BY DIIN
DIIN
External Due In
Internal Due Out
Internal Due In
External Due Out
00419710301
Due Qty 3 OU-Other Unit Committed Stock
Due Qty 3 IU-AinU Exchange

Related

SQL Server performance function vs no function

I have a query (relationship between CONTRACT <-> ORDERS) that I decided to break up into 2 parts (contract and orders) so I can reuse in another stored procedure.
When I run the code before the break up, it took around 10 secs to run; however, when I use a function for getting the contract, then pump the data into a temp table first, then join to the other parts it takes 2m:30s - why the difference in time?
The function takes less than a second to run and returns only one row i.e. details of one contract (contract_id is the parameter supplied to the function).
The part that is most effecting the performance the (ORDERS) largest table in the query has 4.1 million rows and joins to a few other tables however; if I just run the sub query for orders in isolation with a particular filter i.e. the contract id it takes less than a second to run and just happens to return zero records based for the contract I am testing on (due to filtering on the type of order it is looking for).
Base on the above information you would think 1 sec at most for the function + 1 sec at most to get the orders + summarize = 2 seconds at most, not 2 and half minutes!
Where am I going wrong, how do I begin to isolate the issue in time difference?
I know someone is going to tell me to paste the code but surely it is an issue of the database vs indexes perhaps vs how the compiler performs when dealing with raw code versus broken up code into parts. Is there an area of the code I can look at before having to post my whole code as I have tried variations of OUTER APPLY vs LEFT JOIN from the contract temp table to the orders subquery and both give me about the same result. Any ideas?
I don't think the issue was with the code but the network I was running it on. Although bizarre in the fact I had 2 versions of the proc running side by side and yesterday or rather before the weekend one was running in 10 secs and it is still running in 10 secs 3 days later and my new version (using the function) was taking anywhere between 2 to 3 minutes. This morning it is running at 2 or 3 seconds!! So I don't know if it is the fact I changed from declaring my table structure and using a table variable instead first to where previously I was using SELECT ... INTO #Contract made the difference or the network or precompiling has an affect. Whatever it is it no longer an issue. Should I delete this post?

Volume of an Incident Queue at a Point in Time

I have an incident queue, consisting of a record number-string, the open time - datetime, and a close time-datetime. The records go back a year or so. What I am trying to get is a line graph displaying the queue volume as it was at 8PM each day. So if a ticket was opened before 8PM on that day or anytime on a previous day, but not closed as of 8, it should be contained in the population.
I tried the below, but this won't work because it doesn't really take into account multiple days.
If DATEPART('hour',[CloseTimeActual])>18 AND DATEPART('minute',[CloseTimeActual])>=0 AND DATEPART('hour',[OpenTimeActual])<=18 THEN 1
ELSE 0
END
Has anyone dealt with this problem before? I am using Tableau 8.2, cannot use 9 yet due to company license so please only propose 8.2 solutions. Thanks in advance.
For tracking history of state changes, the easiest approach is to reshape your data so each row represents a change in an incident state. So there would be a row representing the creation of each incident, and a row representing each other state change, say assignment, resolution, cancellation etc. You probably want columns to represent an incident number, date of the state change and type of state change.
Then you can write a calculated field that returns +1, -1 or 0 to to express how the state change effects the number of currently open incidents. Then you use a running total to see the total number open at a given time.
You may need to show missing date values or add padding if state changes are rare. For other analytical questions, structuring your data with one record per incident may be more convenient. To avoid duplication, you might want to use database views or custom SQL with UNION ALL clauses to allow both views of the same underlying database tables.
It's always a good idea to be able to fill in the blank for "Each record in my dataset represents exactly one _________"
Tableau 9 has some reshaping capability in the data connection pane, or you can preprocess the data or create a view in the database to reshape it. Alternatively, you can specify a Union in Tableau with some calculated fields (or similarly custom SQL with a UNION ALL clause). Here is a brief illustration:
select open_date as Date,
"OPEN" as Action,
1 as Queue_Change,
<other columns if desired>
from incidents
UNION ALL
select close_date as Date,
"CLOSE" as Action,
-1 as Queue_Change,
<other columns if desired>
from incidents
where close_date is not null
Now you can use a running sum for SUM(Queue_Change) to see the number of open incidents over time. If you have other columns like priority, department, type etc, you can filter and group as usual in Tableau. This data source can be in addition to your previous one. You don't have ta have a single view of the data for every worksheet in your workbook. Sometimes you want a few different connections to the same data at different levels of detail or for perspectives.

Sorting result set according to variable in iReport

I have a resultset with columns:
interval_start(timestamp) , camp , queue , other columns
2012-09-10 11:10 c1 q1
2012-09-10 11:20 c1 q2
interval_start is having values in 10 minutes interval like :
2012-09-10 11:10,
2012-09-10 11:20,
2012-09-10 11:30 ....
using Joda Time library and interval_start field, I have created a variable to create string such that if minutes of interval_start lie between 00-30, 30 is set in minutes else 00 is set in minutes.
I want to group the data as :
camp as group1
variable created as group2
queue as group3
and done some aggregations
But in my report result, I am getting same queue many time in same interval.
I have used order by camp, interval_start, queue but the problem is still exists.
Attaching screenshot for your reference:
Is there any way to sort the resultset according to created variable?
Best guess would be an issue with your actual SQL Query. You say the same queue is being repeated, but from looking at your image it is not actually be repeated it is a different row.
Your query is going to be tough to pull off, as you are really wanting to your query to have an order by of order by camp, (rounded)interval_start, queue. Without that it is ordering by the camp column, and then the non-rounded version of interval_start and then camp. When means that the data is not in the correct order for Jasper Reports to group them the way you want. And then the real kicker is Jasper Reports does not have the functionality to sort the data once it gets it. It is up to the developer to supply that.
So you have a couple options:
Update your SQL Query to do the rounding of your time. Depending on your database this is done in different ways, but will likely required some type of stored procedure or function to handle it (see this TSQL function for example).
instead of having the sql query in the report, move it outside the report, and process the data, doing the rounding and sorting on the java side. Then pass it is as a the REPORT_DATASOURCE parameter.
Add a column to your table to store the rounded time. You may be able to create a trigger to handle this all in the database, with out having to change any of your other code in your application.
Honestly both these options are not ideal, and I hope someone comes along and provides an answer that proves me wrong. But I do not think there is currently a better way.

Crystal Reports Data disappearing

I am currently designing a report in crystal reports.
In the header I have the standard fields like Date/Time and a bunch of variables. In some cases one of the variables does not resolve to anything (it is empty).
When that variable is empty all the report data disappears.
I tried tricking Crystal Reports with creating a formular field, but again no luck!
Any ideas?
All data is received from a MySQL database and the field that causes the trouble is based on a custom query (command).
The actual query:
SELECT `teacher_name`
FROM `class_schedule`
LEFT JOIN (`teacher`, `cs_class`)
ON (`class_schedule`.`class_supporter`=`teacher`.`teacher_id` AND
`cs_class`.`cs_id`=`class_schedule`.`cs_id`)
WHERE `class_id`={?classId}
I have not worked with MySQL much at all. That said, I have never seen that construct for LOJs, so I am questioning the format. Pardon my ignorance if I am uninformed.
If you have CR Developer available, it might be interesting to see what query CR comes up with, and I guess a trace will show what is actually submitted to MySQL.
SELECT `teacher_name`
FROM `class_schedule` cs
LEFT outer JOIN `teacher` tch
on `cs`.`class_supporter`=`tch`.`teacher_id`
Left outer join `cs_class` csc
on `csc`.`cs_id`=`cs`.`cs_id`
WHERE `class_id`={?classId}
is the best I can recommend trying.

Crystal Reports 6.0 Error Code 997

Can anyone describe "Crystal Report Engine Returns Error Code 997" for Crystal Reports 6.0?
Googling proved futile.
Are you using a long datatype in the data source?
If your theory is right, and if you have the long datatype in either a CONNECT BY, GROUP BY, or ORDER BY clause, that could be the culprit. From what I have read, the ORA-00997 error is as follows:
ORA-00997: illegal use of LONG datatype:
Cause: A value of datatype LONG was used in a function or in a DISTINCT, WHERE, CONNECT BY, GROUP BY, or ORDER BY clause. A LONG value can only be used in a SELECT clause.
I have seen Crystal Reports bubble up unhandled SQL Server errors before, so it's possible.