Report Design
 Crystal Reports Forum : Crystal Reports 9 through 2020 : Report Design
Message Icon Topic: Multiple grouping in a report Post Reply Post New Topic
Page  of 2 Next >>
Author Message
premnathk.chn
Newbie
Newbie


Joined: 17 Jan 2008
Online Status: Offline
Posts: 19
Quote premnathk.chn Replybullet Topic: Multiple grouping in a report
    Posted: 28 Jan 2008 at 7:58pm
Hi,
I need to develop a report with the following requirement.
I have to display all the cities and the list of hospitals ,colleges ,hotels etc.This has to grouped by the cities and then by respective categories.

City1
hospital1
hospital2
hospital3

College1
college2
college3
   
hotel1
hotel2
hotel3

City2
.
.
.


Thanks ,
prem




Edited by premnathk.chn - 28 Jan 2008 at 7:58pm
IP IP Logged
BrianBischof
Admin Group
Admin Group
Avatar

Joined: 09 Nov 2006
Online Status: Offline
Posts: 2458
Quote BrianBischof Replybullet Posted: 28 Jan 2008 at 9:44pm
Use subreports. Create a subreport for each group (one for hospitals, one for colleges, etc.)
Please support the forum! Tell others by linking to it on your blog or website:<a href="http://www.crystalreportsbook.com/forum/">Crystal Reports Forum</a>
IP IP Logged
premnathk.chn
Newbie
Newbie


Joined: 17 Jan 2008
Online Status: Offline
Posts: 19
Quote premnathk.chn Replybullet Posted: 28 Jan 2008 at 10:48pm
Thanks brain

I thought of that but there is a problem in it. i have to include this report as a subreport to my main report.
Any thoughts on this?

cheers,
prem
IP IP Logged
BrianBischof
Admin Group
Admin Group
Avatar

Joined: 09 Nov 2006
Online Status: Offline
Posts: 2458
Quote BrianBischof Replybullet Posted: 28 Jan 2008 at 10:57pm
You can't do it then. Sorry.

The one way you could do it, but you need to know SQL is to create a Command object and write a custom SQL query. In the query use a UNION statement to join the different tables together into a single table. I discuss UNION in detail in my book, but the basic idea is to create SELECT statements that retrieve the data you need from each table. But each SELECT statement must return the same number of fields and using the same data types. Then put a UNION between them to make them all appear as a single table.
SELECT City, HospitalName as Col1 FROM table
UNION
SELECT City, CollegeName as Col1 FROM table

That should give you the idea. You can find out a lot more about optimizing SQL in chapter 11 of my book Crystal Reports Encyclopedia.
Please support the forum! Tell others by linking to it on your blog or website:<a href="http://www.crystalreportsbook.com/forum/">Crystal Reports Forum</a>
IP IP Logged
premnathk.chn
Newbie
Newbie


Joined: 17 Jan 2008
Online Status: Offline
Posts: 19
Quote premnathk.chn Replybullet Posted: 28 Jan 2008 at 11:05pm
Brain,

The number of columns for each section would be different in my case.So is there is any other way?

Cheers,
Prem

Edited by premnathk.chn - 28 Jan 2008 at 11:25pm
IP IP Logged
Savan
Senior Member
Senior Member
Avatar

Joined: 14 Dec 2007
Location: India
Online Status: Offline
Posts: 162
Quote Savan Replybullet Posted: 28 Jan 2008 at 11:51pm

Hi Prem

do u have any field which identify wheter the record is college, hospital or hotel. if yes then  u can do a group by on the city field and record type field i.e (college, hospital, hotel). if u dont have a field to identify, please how the data is stored, i can let u know some other way. 
Thanks
Savan
IP IP Logged
premnathk.chn
Newbie
Newbie


Joined: 17 Jan 2008
Online Status: Offline
Posts: 19
Quote premnathk.chn Replybullet Posted: 29 Jan 2008 at 12:00am
Thanks Savan
No i dont have any such identifier.
The Database structure looks like this.

For City:
CityId
CityName
CityCode
StateId(FK)

For College:
CollegeId
CityId(fk)
CollegeName
NoOfStaff
NoOfDept

For Hospital:
HospitalId
CityId(fk)
HospitalName
Nearest Landmark
specialization
...

the report is pulled for a particular State.

Thanks for your efforts
prem


Edited by premnathk.chn - 29 Jan 2008 at 12:01am
IP IP Logged
BrianBischof
Admin Group
Admin Group
Avatar

Joined: 09 Nov 2006
Online Status: Offline
Posts: 2458
Quote BrianBischof Replybullet Posted: 29 Jan 2008 at 9:21am
For tables which don't have any data, just fill it with an empty string. For example, if you need three fields but the table on has two:

SELECT CityName, HospitalName as Field1, "" as Field2 FROM table
Please support the forum! Tell others by linking to it on your blog or website:<a href="http://www.crystalreportsbook.com/forum/">Crystal Reports Forum</a>
IP IP Logged
Savan
Senior Member
Senior Member
Avatar

Joined: 14 Dec 2007
Location: India
Online Status: Offline
Posts: 162
Quote Savan Replybullet Posted: 29 Jan 2008 at 10:00am

i think there is one more way to do by using subreport.

in main report take the table city and group it on city id.  take to subreports for college and hospital. link the college subreport and hospital subreport with city id. in the main report. place the cityname field in group footer and put the college subreport below it. after that put the hospital subreport. so in this way u will get the city name and all the colleges of that city and all the hospitals and then comes the next city.

i have generated this report with dummy data.  please check and let me know if this will solve ur problem.Thumbs%20Up

Thanks
Savan
IP IP Logged
premnathk.chn
Newbie
Newbie


Joined: 17 Jan 2008
Online Status: Offline
Posts: 19
Quote premnathk.chn Replybullet Posted: 29 Jan 2008 at 7:39pm
thanks guys

savan - as i have already told this reports is pulled against a particular state so the main report will have information other than city for eg
main report Layout:
1.Introduction
2.Awards
3.Popular Cities
4.Cutural Heritage & People
.
.
.

So now Popular Cities is the one creating problems for me since its has multiple grouping in it like colleges,hospitals etc.So now if i put a group by cityId in the main report will it give me the correct output? Any way i ll check it and let you know.
Now i have a new problem there is another section in the main report which has multiple grouping like the Popular cities

Thanks,
prem

Edited by premnathk.chn - 29 Jan 2008 at 7:41pm
IP IP Logged
Page  of 2 Next >>
Post Reply Post New Topic
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



This page was generated in 0.016 seconds.