Get specific cell in Crystal Report
I have a Crystal Report linked to table Customer i开发者_开发技巧n SQL Server database. My report generator will execute SELECT SQL and pass the result table into the report as data source.
In the report, I have a field and I want this field to display the cell data at the specific row index and column index of the table (maybe I know the column name). For example, my field should display cell at row 3, column 2 of the data source.
How can I do this using Crystal Report. The latest version now is 2011.
First off, in order for the row number to have any meaning, you'll need to be querying the table with an ORDER BY clause (by sorting the report). Without it, you can't make any assumptions about the "original order of records" in the DB as there really is none.
There are a few ways to get this field depending on where in the report you want to display it. If you simply want to show it in the details section, you can make use of a simple formula like this
if rownumber = 3 then {table.column}
If you'd like to display it instead in a footer, you could make use of a variable instead:
whileprintingrecords;
numbervar thedatavariable;
if recordnumber = 3 then thedatavariable := {table.column}
Throw that formula in the details section of the report and you're then free to use thedatavariable in your footers.
Now for the column: If the column index is NOT dynamic you can just see which column corresponds... for example, if the table's columns are customer_id, customer_name then column 2 will always just be the customer name. If the index number will change, like via a parameter, you could make a formula like this
select {?colIndexParameter}
case 1 : {table.customer_id}
case 2 : {table.customer_name} ...
精彩评论