Solved

CAST Statement

Posted on 2016-08-03
11
28 Views
Last Modified: 2016-08-24
Hi,

I have two fields "Action" & "Action Date" of "Detail_Trans" table.  I need to display three action time based on the different action.

I have created three different action formulas like below:

Formula 1:

If {Detail_Trans.ACTION} = 1 Then {Detail_Trans.ACTION_TIME}

Formula 2:

If {Detail_Trans.ACTION} = 2 Then {Detail_Trans.ACTION_TIME}

Formula 3:

If {Detail_Trans.ACTION} = 3 Then {Detail_Trans.ACTION_TIME}

But my report display duplicate records if it have more than action. I am wondering should I use CASE statement for this. Please advise.

Thanks,
0
Comment
Question by:rowfei
11 Comments
 
LVL 100

Expert Comment

by:mlmcc
ID: 41741645
Duplicate records are generally caused by
1.  Actually having duplicate records in the data source
2.  Having incorrect joins in the data source

Does the report use multiple tables?

mlmcc
0
 

Author Comment

by:rowfei
ID: 41741657
Hi mlmcc,

Yes, the report have multiple tables. I am link main table "Summarry_Trans" to "Detail_Trans" via trans_id.

"Summarry_Trans" table only contains one trans_id. But "Detail_Trans" contains duplicate trans_id because the same trans_id can have different "Action." Below is my report looks like now. I have tried to change left join & inner join, the report results are the same like below.

Trans_ID        Action 1 Date     Action 2 Date   Action 3 Date
123                     2/1/2016            1900/01/01       1900/01/01
123                     1900/01/01        3/3/2016           1900/01/01
123                     1900/01/01        1900/01/01         4/1/2016

Below is what I expect from the report:

Trans_ID        Action 1 Date     Action 2 Date   Action 3 Date
123                     2/1/2016             3/3/2016      4/1/2016

Thanks,
0
 
LVL 10

Expert Comment

by:HuaMinChen
ID: 41741661
Try to put
select distinct ..

Open in new window

on relevant SQL statement
0
Free Tool: Port Scanner

Check which ports are open to the outside world. Helps make sure that your firewall rules are working as intended.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

 

Author Comment

by:rowfei
ID: 41741663
It's built by Crystal Report. How can I add SQL? Thanks,
0
 
LVL 100

Expert Comment

by:mlmcc
ID: 41741673
You are going to need to use a SQL Command rather than the tables directly.

You command will  be something like

SELECT ST.Trans_id, AD1.Action1Date, AD2.Action2Date, AD3.Action3Date
FROM Summarry_Trans ST LEFT OUTER JOIN Detail_Trans AD1 ON ST.Trans_Id = AD1.Trans_Id AND AD1.Action1Date <> Date(1900,01,01)  LEFT OUTER JOIN Detail_Trans AD2 ON ST.Trans_Id = AD2.Trans_Id AND AD2.Action2Date <> Date(1900,01,01)  LEFT OUTER JOIN Detail_Trans AD3 ON ST.Trans_Id = AD3.Trans_Id AND AD3.Action3Date <> Date(1900,01,01)

mlmcc
0
 

Author Comment

by:rowfei
ID: 41741678
Thanks, mlmcc. I have other 10 tables and 15 formulas already built in this report. Is there anyway I can modify the existing three formulas below to limit the duplicate?

Formula 1:

If {Detail_Trans.ACTION} = 1 Then {Detail_Trans.ACTION_TIME}

Formula 2:

If {Detail_Trans.ACTION} = 2 Then {Detail_Trans.ACTION_TIME}

Formula 3:

If {Detail_Trans.ACTION} = 3 Then {Detail_Trans.ACTION_TIME}
0
 
LVL 100

Assisted Solution

by:mlmcc
mlmcc earned 250 total points (awarded by participants)
ID: 41741684
Will Action Dates 1, 2, and 3 always have a date other than 01-10-1900?
Will there only be 1 such date?

You could group on the Trans_id and put formulas in for the dates
Action Date 1
Max({Action1Date}, {Trans_Id)

Action Date 2
Max({Action2Date}, {Trans_Id)

Action Date 3
Max({Action3Date}, {Trans_Id)

mlmcc
0
 

Author Comment

by:rowfei
ID: 41741688
Yes, Action Date always have a date other than 01-10-1900. It only have one date for each action.

I am still confusing about the grouping suggestion above.

Beside the existing three formulas below, I should create another three more for the grouping?

Formula 1:

If {Detail_Trans.ACTION} = 1 Then {Detail_Trans.ACTION_TIME}

Formula 2:

If {Detail_Trans.ACTION} = 2 Then {Detail_Trans.ACTION_TIME}

Formula 3:

If {Detail_Trans.ACTION} = 3 Then {Detail_Trans.ACTION_TIME}
0
 
LVL 100

Assisted Solution

by:mlmcc
mlmcc earned 250 total points (awarded by participants)
ID: 41741710
Group on the Trans_id then put the formulas into the Trans_id group footer to display the data as you desire it.

Delete the dates from the details

mlmcc
0
 
LVL 34

Accepted Solution

by:
James0628 earned 250 total points (awarded by participants)
ID: 41744058
To clarify and correct a couple of things ...

 When mlmcc said to "put the formulas into the Trans_id group footer", I assume that he was referring to the formulas that he posted, not your old formulas.  If you put your old formulas in the transaction group footer, you'll only get a date for whichever Action happens to be in the last record in the group.  The idea is to use your old formulas to produce a date for each Action, and then, in the transaction group footer, display the highest date produced by each of those formulas for that transaction.

 I assume that the Action1Date, Action2Date and Action3Date in mlmcc's formulas should be replaced by your formula names.  He used Max, but that should be Maximum.  And he left out the closing } after Trans_Id.  Rewriting his 3 formulas with those corrections, and more generic terms, they would be:

Maximum ({@your old Action 1 formula}, {transaction group field})

Maximum ({@your old Action 2 formula}, {transaction group field})

Maximum ({@your old Action 3 formula}, {transaction group field})

 Replace the formula and field names with your actual names.


 James
1

Featured Post

Free Tool: ZipGrep

ZipGrep is a utility that can list and search zip (.war, .ear, .jar, etc) archives for text patterns, without the need to extract the archive's contents.

One of a set of tools we're offering as a way to say thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Title # Comments Views Activity
Select Cross-tab total 2 69
Changing Image in report header based on parameter value 12 62
Crystal Reports Format Field with Dashes 6 52
Need to learn crystal reports 7 74
There have always been a lot of questions related to when Crystal Reports evaluates report components (such as formulas, summaries, cross-tabs, charts, to name a few examples). Crystal Reports uses a two-pass reporting process to provide greater …
Hello everyone, Hope you find this as helpful as we did. We have on the company I work for an application built in Delphi V with Crystal Reports 8. We all know that Crystal & Delphi can be temperamental sometimes and the worst thing is, nearly…
Email security requires an ever evolving service that stays up to date with counter-evolving threats. The Email Laundry perform Research and Development to ensure their email security service evolves faster than cyber criminals. We apply our Threat…
In an interesting question (https://www.experts-exchange.com/questions/29008360/) here at Experts Exchange, a member asked how to split a single image into multiple images. The primary usage for this is to place many photographs on a flatbed scanner…

792 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question