Technical Questions
 Crystal Reports Forum : Crystal Reports 9 through 2022 : Technical Questions
Message Icon Topic: Getting Data from 2 Different Years Post Reply Post New Topic
Author Message
carlav60
Newbie
Newbie


Joined: 29 May 2008
Location: United States
Online Status: Offline
Posts: 9
Quote carlav60 Replybullet Topic: Getting Data from 2 Different Years
     Posted: 10 Feb 2009 at 7:56am
I'm sure this is simple to do, but being fairly new to Crystal, I can't figure it out.
 
I need to make a report with data from 2 different years.  All of the data is in one database.  Using the select expert, I can get data for an individual year, but I don't know how to get the data for 2 different years in one report.
 
Example:
 
Account      Prior Yr Amt      Current Yr Amt
 
Thank you for your help.
Crystal 11
IP IP Logged
lockwelle
Moderator
Moderator


Joined: 21 Dec 2007
Online Status: Offline
Posts: 4374
Quote lockwelle Replybullet Posted: 10 Feb 2009 at 8:52am
Alas, I don't use the select expert, but I would guess that if you can get for 1 year, I would try adding another criteria for the other year and then see if there is a way to 'OR' them together.
 
If possible, I would advise using a stored procedure as this will give you maximum versatility.  Barring that, I would try to write the SQL select yourself as you seem to be looking for something like:
SELECT Account, year FROM sometable WHERE year = currentYear - 1 OR year = currentYear
 
Hope this helps
IP IP Logged
Handsome-Hal
Newbie
Newbie
Avatar

Joined: 06 Feb 2009
Location: United States
Online Status: Offline
Posts: 7
Quote Handsome-Hal Replybullet Posted: 10 Feb 2009 at 12:21pm
In selection Expert choose the "Year" and then choose "Greater than Or Equal to" ...then enter the previous year.

But your detail for each amount will have to be an "IF Then" formula.

if year = previous year then Amount.

if year = current year then Amount.


IP IP Logged
hilfy
Admin Group
Admin Group
Avatar

Joined: 20 Nov 2006
Online Status: Offline
Posts: 3702
Quote hilfy Replybullet Posted: 10 Feb 2009 at 2:59pm
From experience, neither of these suggestions will work for the format that you're looking for with the prior year and the current year on the same line.
 
However, Crystal will allow you to pull multiple copies of the same table into a report.  In the Database Expert, when you select a table that is already on the report, Crystal will notify you and ask you if you want to "alias" it.  If you say Yes, it will add a second copy of the table with "_1" added to the end of the name.  For this example, I'll call them Table and Table_1.
 
Link from Table to Table1 based on account number or whatever unique field or set of fields identify an account.  If you want all of the accounts with amounts from this year to appear on the report regardless of whether they have values from the previous year, right-click on the link and select Link Options.  Select "Left Outer Join" and click on OK.
 
In the Select Expert, set whatever your various non-year-based selection criteria is for Table only.  Set the year criteria for Table to the current year.  Set the year criteria for Table_1 to the prior year.
 
In your report, group on {Table.Account_Number}.
 
-Dell
 
IP IP Logged
carlav60
Newbie
Newbie


Joined: 29 May 2008
Location: United States
Online Status: Offline
Posts: 9
Quote carlav60 Replybullet Posted: 11 Feb 2009 at 8:08am
hilfy - You're the best!  That worked!
 
Thank all of you for your responses.
 
Carla
IP IP Logged
Printable version Printable version

Forum Jump
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot delete your posts in this forum
You cannot edit your posts in this forum
You cannot create polls in this forum
You cannot vote in polls in this forum