How to Get distinct value from one column in Crystal Report - crystal-reports

My Requirement is I need to take all distinct value from one column and to display
in Report Header section.
For eg.
Year
2008
2009
2010
2008
2009
It must print like 2008,2009,2010 in Report Header section.

You could use a subreport, then select the distinct years and print them or write them in a shared variable to use them in your main report.
To select only the distinct values either
use a command as a datasource select distinct year from yourtable
check Database | Select Distinct Records in the menu for the subreport

Related

SQL SSRS aggregate fuctions

I am trying to figure out the aggregate functions in SQL SSRS to give me to sum of total sales for the given information by YEAR. I need to combine the year, the months within that year and provide the total sum of sales for that year. For example: for 2018 I need to combine month's 2-12 and provide the total sum, for 2019 combine 1-12 and provide total sum and so on.
enter image description here
I'm not sure where to begin on this one as I am new to SQL SSRS. Any help would be appreciated!
UPDATE:
Ideally I want this to be the end result:
id Year Price
102140 2019 ($XXXXX.XX)
102140 2018 ($XXXXX.XX)
102140 2017 ($XXXXX.XX)
And so on.
your query:
Select customer_id
, year_ordered
--, month_ordered
--, extended_price
--, SUM(extended_price) OVER (PARTITION BY year_ordered) AS year_total
, SUM(extended_price) AS year_total
From customer_order_history
Where customer_id = '101646'
Group By
customer_id
, year_ordered
, extended_price
--, month_ordered
Provides this:
enter image description here
multiple "years_ordered" because it is still using each month and that months SUM of price.
There are two approaches.
Do this in your dataset query:
SELECT Customer_id, year_ordered, SUM(extended_price) AS Price
FROM myTable
GROUP BY Customer_id, year_ordered
This option is best when you will never need the month values themselves in the report (i.e. you don't intend to have a drill down to the month data)
Do this in SSRS
By default you will get a RowGroup called "Details" (look under the main design area and you will row groups and column groups).
You can right-click this and add grouping for both customer_id and year_ordered. You can then change the extended_price textbox's value property to =SUM(Fields!extended_price.Value)
You could use a window function in your SQL:
select [year], [month], [price], SUM(PRICE) OVER (PARTITION BY year) as yearTotal
from myTable

Add Heading to a group of columns in Oracle SQL

Oracle 11g. Oracle Apex 5.1
I need to Merge the columns without merging the data and Add a column heading in Oracle Apex Interactive Report.
For Example
I have a table like this:
I want the table output like this:
How can I achieve the output in Report Select Statement?
If I am using below query in Oracle Apex Interactive Report:
TITLE LEFT ' amount_column Quantity_column'
SELECT Date, Amount1, Amount2, Amount3, Quantity1, Quantity2
FROM table_name;
I am getting error as: ORA-20001: Query must begin with SELECT or WITH.
In oracle Apex 5.1 we can create such groups in Interactive Grid(IG).
To create a group, steps are:
Go to Attribute of IG -> create Group -> add a name to group.
To assign a group on column, steps are:
go to particular column(s) name -> under layout property -> select group name
Save and run the page and it will work.
If you are running the query to get a SQL/Plus style textual output (using Crtl-F5 / run-as-script within SQL Developer) then you can use the commands for formatting SQL*Plus reports such as COLUMN and TTITLE to make it appear like your desired result:
Something like (untested):
COLUMN "Date" FORMAT A9
COLUMN Amount1 FORMAT 9999.99
COLUMN Amount2 FORMAT 9999.99
COLUMN Amount3 FORMAT 9999.99
COLUMN Quantity1 FORMAT 999999999
COLUMN Quantity2 FORMAT 999999999
TTITLE LEFT ' Amount column Quantity Column'
SELECT "Date", Amount1, Amount2, Amount3, Quantity1, Quantity2
FROM table_name;
If you want to do it in the grid (using F5 to run the query within SQL Developer) then you are out of luck and it is not possible.

SSRS Multivalued parameter

I have a report in ssrs 2008 r2.I have created two multi-valued parameter on my report like fiscal period (value is 08,09,10,11) and parentname(in which there are multiple parent like a,b,c,d...).A user can select single value or multiple value of his choice.I have create seprate dataset for each to populate its value.Both have datatype 'Text'.
Now uderlying query is something like this:
selet * from table where fiscal period in(#fiscalperiod) and parentname in(#parentname)
If I run this query manually in sql then I wrote query like
select * from table where fiscalperiod in('09','10') and parentname in('a','b''c')
Now my question is Is ssrs run the dataset query of report in this way like 'a','b''c' that means comma seprated value.
Since Parameter is multi-valued, Query will be run like 'a','b','c'
selet * from table where fiscal period in(#fiscalperiod) and parentname in(#parentname)
If you select fiscal period: 08, 09 and parentname: a, b then query will be executed internally like
selet * from table where fiscal period in('08', '09') and parentname in('a', 'b')

Table Aggregation strategy (SSIS / Stored procedure / SSRS)

I have a table with roughly 7,000,000 records.
It's very flat and for sake of argument it has 3 columns I wish to aggregate on. This aggregation should very simply create a count /pivot of each instance of that value.
E.G
Company Status Year
Hatstand Open 2011
Hatstand Closed 2011
Moonbase Open 2011
Would produce
Count of Hatstand **2**
Count of Hatstand Open **1**
Count of Hatstand Open 2011 **1**
So it's a very simple count of each "branch" of data.
My first choice was to use a SSRS Matrix control. Which when testing with a small dataset worked really well. However when using a the full data-set would not run.
What is the "correct" way to approach this problem?
Should I pre-aggregate via a stored procedure or SSIS job?
Or should I continue with the SSRS route and try to refine my query?
Thanks
T-SQL is preferred way to go if You are using SQL Server 2005 or 2008.
If You are using SQL Server 2005 or 2008 You can try:
SELECT *, COUNT(*) FROM TBL
GROUP BY COMPANY, STATUS, YEAR
WITH ROLLUP -- or WITH CUBE
If You are using SQL Server 2008 You can try with :
SELECT *, COUNT(*) FROM A
GROUP BY
GROUPING SETS (
(COMPANY),
(COMPANY, STATUS),
(COMPANY, STATUS, YEAR)
)
For details about GROUP BY WITH ROLLUP/CUBE and GROUPING SETS take a look at GROUP BY.

SQL like Ranking functions in Crystal Reports

Is there a way to do ranking functions in Crystal Reports running against a SQL 2000 server?
http://msdn.microsoft.com/en-us/library/ms189798.aspx
I need to return the row number on table A before joining it to table B in Crystal Reports.
Thanks.
You can embed 'raw' SQL in a SQL Expression field. It must be a scalar value, however. See Crystal Reports: Using SQL Expression Fields.
You can do a running totals-style or row count formula on the data in the report itself. If you need to differentiate between table A and B's data then you can insert a constant into the select statements (do you mean join or union?) and then key on that field in your formula.