How do I do a CR-type formula in SQL Server Reporting services? - crystal-reports

In Crystal Reports, I could define a formula that would evaluate for each detail line. For example, if I had a query that would return a PatientId, an ObsTerm name, and an ObsTerm value, I could define a formula called {#Hispanic} that had the value:
If {Command.OBSNAME} = "HISPANIC" Then
{Command.OBSVALUE}
Else
" "
Then, in the group footer, I could take Maximum({#Hispanic}, {Command.PATIENTID}) to see if I had gotten a value returned for the patient's ethnicity - either I'd get the value (assume only one, since that's how I built the query) or a blank.
I'm trying to convert a CR report over to SSRS 2008R2: how would I do the above? Thanks.

Add a calculated field to your data source (called 'Hispanic' or whatever) with a formula of:
=IIF(Fields!OBSNAME.Value="Hispanic",Fields!OBSVALUE.Value,"")
In your report, add a parent group to your detail row and type [Max(Hispanic)] into a field in the group row. You may then want to hide the detail row and show only the aggregate data. I think there's probably a much easier way to do what you want but it's not clear from your question.
I made the transition from Crystal to SSRS and it is a hard road. You need to unlearn all your Crystal (especially formatting).

Related

jasper report show count on footer of a specific query

am very new to jasper report
also I have tried looking at videos but can not seem to get this one concept
basically there is this main query which i have
select * from table
which is populated in the details area
however i want a second query
select count(*) from table where name = "tim"
and put the count on the footer
can this be done using jasper
any tutorial to this concept or guidance would be helpful
to sum up the details area should show all the data where as the footer should only show counts of a few things.
You can only have one DataSet (therefore query) for the report. In your case this is your main report select * from table, which seems to be working well.
You have two options for adding the information you want:
(and I would say the better option) is to add a variable $V{tim_count} which is configured as:
initial value 0
expression value "tim".equals($F{name}) ? 1 : 0"
calculation function sum
there are multiple ways to increment this variable, so I'll leave that with you. In the footer you would then add a text field with the $V{tim_count} variable as it's contents.
You can read about variables here https://community.jaspersoft.com/wiki/variables
You can add an object that has it's own DataSet:
Table
List
Subreport
You would then be able to add your query to that object and display it appropriately. As you can see, displaying a COUNT is not really the most appropriate way to do this.
Note - I don't suggest this way

Displaying multiple records in Crystal report as comma separated value

I have a view that I am using to display some information in Crystal report file. In some cases, view is supposed to return more than 1 record.
By default, in these cases, Crystal report take the last record and display that one. So, if I have two records with id A and B, I will see only the details of B.
I want to have an option where both A and B are displayed separated by comma.
E.g. if EmployeeDepartment in Employee table has two records (CIS, FINANCE) for employee A, then I want to see #EmployeeDepartment return "CIS, FINANCE" instead of just "FINANCE".
I have been trying to find a way to do this. Till now, I have gotten this far:
Base formula
Shared Stringvar store;
store:=store+{TBL_MR_Header.MRHD_Customer_Ref_No}+ ", "
Display formula
Shared Stringvar store;
store
When I run the report, base formula returns "B," instead of "A,B". Display formula on the other hand displays nothing.
I am unsure what I am missing here.
Edit:
I have created a query that returns the two value comma separated, in both records. So, both records display "CIS, FINANCE" instead of "CIS" and "FINANCE" respectively. Now, I have simple problem, how do I put this query in crystal report file? Only option I can find is to use that datasource expert tool but that does not allow updating query.
Edit:
I actually decided to go different route there. I tried putting the base formula in header and display formula in detail section, but that didn't work either. Turns out, one of my colleague tried a trick to solve similar problem. He used the C# code to call a T-SQL query, got the value in CSV format, and passed it as a parameter. It requires an extra trip to database, but it made it easier.

crystal report problem

what is the equivalant command like in vb for EOF(), MoveNext, Moveprevious commands in crystal reports
There are no equivalent answers in Crystal Reports, at least not in the versions I have used. Crystal Reports more or less simply dumps the data out into the report.
That said, if you are in a detail row, and you want to find out what the next value of a field will be, you can use:
next({YourColumn})
You can also find out the previous column value by using this:
previous({YourColumn})
Keep in mind that Next() won't work on the last record, and Previous() won't work on the first record.
I'll have to double-check, but I believe there is an OnLastRecord function that returns TRUE if you are on the last record.
First, welcome to SO!
Second, you sound new to Crystal Report's purpose is to display data, not perform the kind of calculations you're talking about. CR usually goes record-by-record through the data, displaying (or suppressing) each record, and adding group headers & footers.
To answer your question, LittleBobbyTables does give a few good pointers. To see the entire list of functions available to you, there is a list in the Formula Editor (see pic below). Press F1 for detailed descriptions of each command.
You can also:
Create a "Running Total Formula" that will evaluate each record and give a calculation in the group footer.
Do the calculations outside of Crystal Reports and only feed the end result in (perhaps with an unlinked join to your primary table).
The most complex option is to make a subreport that does the calculation and feeds the result back to the main report
Can you give us some more details about what you're trying to do?

Crystal Report-Running Total

I have a problem with running Total in Crsystal report9
if their is no values available for a Paticular field how can we return the running total as '0'
Instead of display the Running Total directly in your report create a Formula Field based on the Running Total and drag it into the report.
Your formula should look like this (Crystal Syntax)...
if ISNULL({#RunningTotalField}) then
"0.00"
else
ToText(RunningTotalField, 2)
If there is no data for that particular group, then Crystal won't show it easily. Your options are :
1) Use subreports to display the values for a particular group, and keep the main report just looking at the table(s) containing the group headers.
2) Use a stored procedure as the source so you have full control over the SQL that is run.
The problem is that as soon as you use a field to group, Crystal will only return records where that field has been used. If it was simply in the Details section you could modify the link to a LEFT JOIN and it wouldn't matter, but the group forces the INNER JOIN which means the groups without data are not returned.
Unfortunately Running Totals don't show up if there are no records that match your criteria. An alternative is to use a set of formulas calculated in various sections of the report. The technique is widely described in the Crystal literature. For example, this TekTips gives a very succinct overview of your options.
You set up an initialising formula in each header, with the evaluation time directive "WhilePrintingRecords". This approach was the only one available for doing running totals in the "good ol' days" before RunningTotal objects were available.

Crystal Reports: Is it possible to sum for more than one column?

I work on an accounting project in .NET.
I want to sum all transaction and its opening balances.
I use summary but it Allows only one column..
You can summarize within formulas, so long as the formula field is present in the report footer. When using Sum() CR knows to evaluate the expression for all records returned.
So you would create a formula for the report footer, and the formula code would be something like:
Sum({#TransactionAmt1}) + Sum({Transactions.Amount}) + Sum({#AnotherFormula});