Question

This Crystal Report program was dumped on my lap and I'm brand new to it. I understand the concept, but I'm hitting a wall here.

There is another question that's similar: Crystal Reports equivalent of 'WHERE'

But it and the answers are directed towards (it seems) "totaling" the column, whereas I want to simply only show the row if one of the columns (in this case, if "CostType" is equal to 0).

I have two data tables I'm reading from to create this report. They're joined via a common column name (ItemKey). Unfortunately, in the second table, there are multiple records of the same item. I only want the item(s) with a CostType of 0.

This is stupidly easy in SQL, even for a beginner like me, but I can't figure out how to effectively say: "only show an item if the CostType is 0" with Crystal Reports.

Item_Cost Table (example):

ItemKey      Special         Cost         CostType
001          TRUE            55.00        0
002          FALSE           10.00        0
003          TRUE            20.00        1

Item Table (example):

ItemKey      Description     Mode  
001          Whatever        EE 
002          Random          AB 
003          Unimportant     GE

What shows up:

Item         Description     Mode  
Box          Whatever        EE 
Square       Random          AB 
Circle       Unimportant     GE

What I want to show:

Item         Description     Mode  
Box          Whatever        EE 
Square       Random          AB 

I hope this all makes sense. Basically, if this was a SQL query, I'd just say "WHERE CostType = 0" at the end and I wouldn't get all of the other items that have different cost types.

I should mention that this is entirely handled by Crystal Reports. I'm not using a SQL string and passing it in or something. The function for showing the window is as follows:

    Dim PartsDemandReport As CrystalDecisions.CrystalReports.Engine.ReportDocument = New crptIndentedBomXLBom
    PartsDemandReport.SetDataSource(GLOBAL_VARIABLES.GlobalBomIndented)

    Dim CrystalReportViewerForm As New frmCrystalReportViewer
    CrystalReportViewerForm.CrystalReportViewer1.ReportSource = PartsDemandReport
    CrystalReportViewerForm.Show()
    PartsDemandReport = Nothing

If there's a way to simply force Crystal Reports to add that "WHERE CostType = 0", that'd be great. Thanks in advance.

Was it helpful?

Solution

There are couple of ways to do this:

  1. If you don't need the CostType not equal to 0 in whole report then you can directly give in select expert which acts as where clause for crystal reports.

Example:

go to Report ---> Selection Formula ---> Record this open formula window in that add below line

CostType = 0

This will ensure only cost type = 0 will be retrived from database

2.If you require cost type <> 0 any where in report. Then add below condition for Item, Description and Mode Columns

Example

@Item:

if cost type = 0 
then <<Database Item field >>

Place it in detail part of Item column.

In the same way do for other columns as well.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top