Solved

CAST Statement

Posted on 2016-08-03
11
23 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
 

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
Highfive + Dolby Voice = No More Audio Complaints!

Poor audio quality is one of the top reasons people don’t use video conferencing. Get the crispest, clearest audio powered by Dolby Voice in every meeting. Highfive and Dolby Voice deliver the best video conferencing and audio experience for every meeting and every room.

 

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

Do You Know the 4 Main Threat Actor Types?

Do you know the main threat actor types? Most attackers fall into one of four categories, each with their own favored tactics, techniques, and procedures.

Join & Write a Comment

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…
This video gives you a great overview about bandwidth monitoring with SNMP and WMI with our network monitoring solution PRTG Network Monitor (https://www.paessler.com/prtg). If you're looking for how to monitor bandwidth using netflow or packet s…
When you create an app prototype with Adobe XD, you can insert system screens -- sharing or Control Center, for example -- with just a few clicks. This video shows you how. You can take the full course on Experts Exchange at http://bit.ly/XDcourse.

757 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

Need Help in Real-Time?

Connect with top rated Experts

20 Experts available now in Live!

Get 1:1 Help Now