Report Design
 Crystal Reports Forum : Crystal Reports 9 through 2022 : Report Design
Message Icon Topic: Parameter to select Table Post Reply Post New Topic
Author Message
jsnyderdbs
Newbie
Newbie
Avatar

Joined: 27 Apr 2011
Location: United States
Online Status: Offline
Posts: 4
Quote jsnyderdbs Replybullet Topic: Parameter to select Table
     Posted: 27 Apr 2011 at 7:13am

I have an issue with efficiency. I have a database that stores all monthly transactions in a separate table. The table structure is identical but the table name ends in the month number i.e. Reports1 for January’s information and Reports12 for December’s.

I want to be able to select data from a range of dates that may span several months. I have successfully created a report that does a union all for all twelve tables but the system then needs to read all the data from all twelve tables. If I want a report for a one-week period and the week spans 2 months, I would be reading 12 months of data. I am selecting all data from the table where the date is between the variables I have setup. But I want a variable that only selects the desired table…

Help

IP IP Logged
hilfy
Admin Group
Admin Group
Avatar

Joined: 20 Nov 2006
Online Status: Offline
Posts: 3702
Quote hilfy Replybullet Posted: 27 Apr 2011 at 11:42am
What type of database are you connecting to.  If it's a client/server database such as MS SQL Server or Oracle, you could do this in a stored procedure that returns a cursor (set of records) that your report will read.
 
-Dell
IP IP Logged
jsnyderdbs
Newbie
Newbie
Avatar

Joined: 27 Apr 2011
Location: United States
Online Status: Offline
Posts: 4
Quote jsnyderdbs Replybullet Posted: 28 Apr 2011 at 2:39am
Connecting to a SQL database. Most of my customers are satisfied with a monthly summary and that was not hard to create but one wants to allow this report to pick a starting date and an ending date and that information can be in any one of those 12 tables that were picked. currently i have this script:
 

SELECT * FROM REPORTSQL1 where Reportdate between {?startdate} and {?enddate}

UNION ALL SELECT * FROM REPORTSQL2 where Reportdate between {?startdate} and {?enddate}

UNION ALL SELECT * FROM REPORTSQL3 where Reportdate between {?startdate} and {?enddate}

UNION ALL SELECT * FROM REPORTSQL4 where Reportdate between {?startdate} and {?enddate}

UNION ALL SELECT * FROM REPORTSQL5 where Reportdate between {?startdate} and {?enddate}

UNION ALL SELECT * FROM REPORTSQL6 where Reportdate between {?startdate} and {?enddate}

UNION ALL SELECT * FROM REPORTSQL7 where Reportdate between {?startdate} and {?enddate}

UNION ALL SELECT * FROM REPORTSQL8 where Reportdate between {?startdate} and {?enddate}

UNION ALL SELECT * FROM REPORTSQL9 where Reportdate between {?startdate} and {?enddate}

UNION ALL SELECT * FROM REPORTSQL10 where Reportdate between {?startdate} and {?enddate}

UNION ALL SELECT * FROM REPORTSQL11 where Reportdate between {?startdate} and {?enddate}

UNION ALL SELECT * FROM REPORTSQL12 where Reportdate between {?startdate} and {?enddate}

This works but lets say i wanted to do a report for March 28 through April 1 (Monday through Friday) Crystal has to read all twelve months of data to provide 5 days of information.  I want a way that it will only pull this data from REPORTSSQL3 and REPORTSSQL4
 
Again the table structure is identical and state and federal regulations  require monthly reports that the sytem istself generates so it is quite easy to provide monthly data, it is spanning months that I would like to do without having to read all twelve tables unless they want a yearly report.
 
Thanks,
Jeff
IP IP Logged
hilfy
Admin Group
Admin Group
Avatar

Joined: 20 Nov 2006
Online Status: Offline
Posts: 3702
Quote hilfy Replybullet Posted: 28 Apr 2011 at 2:58am
There is no simple way to do this in a select statement.  The only way I can think of is to create a stored procedure that generates and runs a dynamic SQL statement that only contains the required tables based on the dates selected.
 
-Dell
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