Still celebrating National IT Professionals Day with 3 months of free Premium Membership. Use Code ITDAY17

x
?
Solved

CAST Statement

Posted on 2016-08-03
11
Medium Priority
?
34 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
11 Comments
 
LVL 101

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 11

Expert Comment

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

Open in new window

on relevant SQL statement
0
Hire Technology Freelancers with Gigs

Work with freelancers specializing in everything from database administration to programming, who have proven themselves as experts in their field. Hire the best, collaborate easily, pay securely, and get projects done right.

 

Author Comment

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

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 101

Assisted Solution

by:mlmcc
mlmcc earned 1000 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 101

Assisted Solution

by:mlmcc
mlmcc earned 1000 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 35

Accepted Solution

by:
James0628 earned 1000 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

On Demand Webinar: Networking for the Cloud Era

Ready to improve network connectivity? Watch this webinar to learn how SD-WANs and a one-click instant connect tool can boost provisions, deployment, and management of your cloud connection.

Question has a verified solution.

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

Crystal Reports: 5 Tests for Top Performance It is complete, your masterpiece report.  Not only does it meet your customer’s expectations, it blows them out the water, all they want is beautifully summarised and displayed in a myriad of ways. …
I hate sub reports and always consider them the last resort in any reporting solution.  The negative effect on performance and maintainability is just not worth the easy ride they give the report writer.  Nine times out of ten reporting requirements…
Monitoring a network: how to monitor network services and why? Michael Kulchisky, MCSE, MCSA, MCP, VTSP, VSP, CCSP outlines the philosophy behind service monitoring and why a handshake validation is critical in network monitoring. Software utilized …
Visualize your data even better in Access queries. Given a date and a value, this lesson shows how to compare that value with the previous value, calculate the difference, and display a circle if the value is the same, an up triangle if it increased…

722 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