Crystal reports - read from a table and perform calculations - crystal-reports

Using Oracle - I'm looking for a way to sum records for over multiple rows and multiple tables
Example:
SQL (without using Crystal) looks something like this:
SELECT D.REC ,D.CODE,
(SELECT SUM(AMT)
FROM TableT T2
WHERE T2.DELETED = 0
AND D.REC = T2.RID
AND T2.TYPE = 65
AND T2.RES <> 10
AND LOT = 6) AS T2Total
FROM TableD D
WHERE D.DELETED=0
GROUP BY D.CODE, REC
ORDER BY D.CODE
There are more subselects and calculations in which I am no longer reading from 2 tables, but 4 and the records selected no longer have the same relationship and I was wondering if there was a way for me to write this in Crystal, I haven't found a way to create a stored proc for this
Any ideas/help is much appreciated.

Best way in my opinion would be creating a VIEW for such scenarios. Add whatever you want to the view and then use the view in your report.

Related

Power BI Or SQL function for iterating through rows, finding null in cell and then deleting all rows with same identifier

I am trying to find the best way to clean my data using either T-SQL or a tool within Power BI.
included is a snippet of my data, I would usually do this in Excel using multiple tables & VLOOKUP however my data set contains 2+ million Rows so this isn't an option.
I need a function that:
Iterates through each row looking at each 'SiteID'
checks related 'flow' value for 'NULL' or '0'
If 'NULL' or '0' finds all the rest of the 'SiteID's' with the same value in the full data set in the rows above or below
Removes all rows with matching 'ID'S' Regardless if any other 'null' or actual value exists
Moves onto next record checking same & continuing iteration of complete data set
is this something which is possible? thanks for any advice or help :)
Sample data values
I want to add another thing, if you have a million rows of data, iteration is not a good option to think about. I guess all you want is to remove records having Null or 0 in flow. I perfer to use CTE just to be clear in logic.
;WITH deletion AS
(
SELECT SiteID
FROM Table1
WHERE Flow = 0 or Flow is null
)
DELETE T
FROM Table1 T
INNER JOIN Deletion D on T.SiteID = D.SIteID

Azure Data Flow filter distinct rows

What I want to achieve is that I have sources which sending me some data, but before saving that data in sink I want to filter that distinct with respect to columns I am not able to find Distinct function in expression functions. Can anyone tell me how to achieve this
Not sure if you still have this problem, I suggest to use the 'Aggregate' component in dataflow, I did a test like below:
in 'Aggregate Settings' we define all the 'Group by' columns and 'Aggregates' columns, the source table have 9 columns in total, and 900 rows in total containing 450 distinct rows plus 450 duplicated rows.
I use max to aggregate the 'ModifiedDate' column, and in sink table there's only 450 distinct rows.
This can be done by manually editing the script (and then linking it together on the UI).
The following snippet does a distinct filtering using all columns:
aggregate(groupBy(mycols = sha2(256,columns())),
each(match(true()), $$ = first($$))) ~> DistinctRows
https://learn.microsoft.com/en-us/azure/data-factory/data-flow-script#distinct-row-using-all-columns

Crystal Reports - Create subreport with column range [col1...col60] as datasource?

I am adept in both SQL and CR, but this is something I've never had to do.
In CR, I load a table that will always contain 1 record. There is a range of columns (like Column1, Column2 ... Column60). (bad design, I know, but I can't do anything to change that).
Thanks to this old design I have to manually add each column in my report like this:
-----------
| TABLE |
-----------
| Column1 |
| Column2 |
| Column3 |
| ... |
-----------
Now I would like to be able to create a subreport and create a datasource for it in such a way that [Column1...Column60] becomes a collection [Row1...Row60]. I want to be able to use the detailsection of the subreport to dynamically generate the table. That would save me a lot of time.
Is there any way to do that? Maybe a different approach to what I had in mind?
Edit
#Siva: I'll describe it the best way I can. The table exists out of 500+ columns and will only hold 1 record (never more). Because normalization was never taken into account when creating these tables (Objective C / DBF ages) columns like these: Brand01,Brand02,Brand03...Brand60 should have been placed in a separate table named "Brands"
The document itself is pretty straight forward considering there's only one record. But some columns have to be pivoted (stacked vertically) and placed in a table layout on the document which is a lot of work if you have to do it manually. That's why I wanted to feed a range of columns into my subreport so I can use the detail section of my subreport to generate the table layout automatically.
Ok got it... I will try to answer to the extent possible...
you need to have 2 columns in report that will show the 60 column names as 60 rows as 1st column and 60 column data as 2nd column. For this there are two ways that I can think of.
if columns are static and report need to be developed only once then though its a tough job manually create 120 formulas 60 for row names where you will write column names and 60 for data for respective columns and place in report since you have only one record you will get correct data. Like below:
formula 1:
column1 name // write manually
Formula 1:
databasefield for column1 // this has data for column1
Above will be one row in report like this you will get 120 formulas 60 rows and you don't need sub report here main report will do the job.
Since you are expecting dynamic behavior (Though columns are static), you can create view from database perspective or datatable (Please note I have no idea on datatable use it as per your convinience).
Create in such a way that it has 2 columns in table and in report use cross tab that will give you dynamic behaviour.
In cross tab column1 will be rows part and column 2 will be data.
Here also I don't see any requirement for sub report you can directly use main report. If you want sub report you can use aswell no harm since you have only 1 record

Combining 2 or more datasets onto the same Line Chart SQL Server 2008 R2

I am fairly knew to SQL Report Builder and I currently have four different DataSets that are displaying data on 4 line charts. I want to be able to combine these all into 1 chart with 4 different lines.
Here is my example query for one of my data sets.
SELECT
QA_Automation_Datalogs_1.Log_Time,
QA_Automation_Datalogs_1.Y_Bed_Position,
FROM
QA_Automation_Datalogs_1
WHERE
QA_Automation_Datalogs_1.Location = #Plant AND
QA_Automation_Datalogs_1.Log_Time >= #start_date AND
QA_Automation_Datalogs_1.Log_Time < #stop_date AND
QA_Automation_Datalogs_1.Bed_Number = 1
ORDER BY
QA_Automation_Datalogs_1.Log_Time
For the different data sets I am changing the WHERE Bed_Number to 1,2,3, and 4.
I then am graphing the bed position as a function of time. I have tried using both Lookup functions and JOIN/UNION functions but they have not been working( could be due to some syntax errors). I also am not able to change how the data is arranged in the server.
Sorry I forgot to mention that after I get the data I create a calculated field "Position" and set it equal to "Y_Bed_Position". I then am graphing the Sum(Fields!Position.Value). If I obtain all the data at once like I believe you have shown me, I am not sure how to Sum() each individual bed together.
I might be missing something, but as I understand your question I think this should get the data you seek.
SELECT
QA_Automation_Datalogs_1.Log_Time,
QA_Automation_Datalogs_1.Bed_Number,
QA_Automation_Datalogs_1.Y_Bed_Position,
FROM
QA_Automation_Datalogs_1
WHERE
QA_Automation_Datalogs_1.Location = #Plant AND
QA_Automation_Datalogs_1.Log_Time >= #start_date AND
QA_Automation_Datalogs_1.Log_Time < #stop_date AND
QA_Automation_Datalogs_1.Bed_Number in (1, 2, 3, 4)
ORDER BY
QA_Automation_Datalogs_1.Log_Time,
QA_Automation_Datalogs_1.Bed_Number

Reporting on multiple tables independently in Crystal Reports 11

I am using Crystal Reports Developer Studio to create a report that reports on two different tables, let them be "ATable" and "BTable". For my simplest task, I would like to report the count of each table by using Total Running Fields. I created one for ATable (Called ATableTRF) and when I post it on my report this is what happens:
1) The SQL Query (Show SQL Query) shows:
SELECT "ATABLE"."ATABLE_KEY"
FROM "DB"."ATABLE" "ATABLE"
2) The total records read is the number of records in ATable.
3) The number I get is correct (total records in ATable).
Same goes for BTableTRF, if I remove ATableTRF I get:
1) The SQL Query (Show SQL Query) shows:
SELECT "BTABLE"."BTABLE_KEY"
FROM "DB"."BTABLE" "BTABLE"
2) The total records read is the number of records in BTable.
3) The number I get is correct (total records in BTable).
The problems starts when I just put both fields on the reports. What happens then is that I get the two queries one after another (since the tables are not linked in crystal reports):
SELECT "ATABLE"."ATABLE_KEY"
FROM "DB"."ATABLE" "ATABLE"
SELECT "BTABLE"."BTABLE_KEY"
FROM "DB"."BTABLE" "BTABLE"
And the number of record read is far larger than each of the tables - it doesn't stop. I would verify it's count(ATable)xcount(BTable) but that would exceed my computer's limitation (probably - one is around 300k rows the other around 900k rows).
I would just like to report the count of the two tables. No interaction is needed - but crystal somehow enforces an interaction.
Can anyone help with that?
Thanks!
Unless there is some join describing the two tables' relationship, then the result will be a Cartesian product. Try just using two subqueries, either via a SQL Command or as individual SQL expressions, to get the row counts. Ex:
select count(distinct ATABLE_KEY) from ATABLE
If you're not interested in anything else in these tables aside from the row counts, then there's no reason to bring all those rows into Crystal - better to do the heavy lifting on the RDBMS.
You could UNION the two queries. This would give you one record set containing rows from each query once.