Report Design
 Crystal Reports Forum : Crystal Reports 9 through 2020 : Report Design
Message Icon Topic: Report Run Multiple Times for Different Users Post Reply Post New Topic
Author Message
zbumpers
Newbie
Newbie
Avatar

Joined: 13 Oct 2015
Location: United States
Online Status: Offline
Posts: 2
Quote zbumpers Replybullet Topic: Report Run Multiple Times for Different Users
    Posted: 15 Oct 2015 at 6:33am
I am trying to run a report to pull data for the 10 most active clients and the 10 least active clients for each sales rep.
How do I get the report to select each sales rep and pull their data? The query works if I hard code one sales rep ID into the sql code.
IP IP Logged
praveeng
Senior Member
Senior Member
Avatar

Joined: 11 Jul 2011
Online Status: Offline
Posts: 165
Quote praveeng Replybullet Posted: 16 Oct 2015 at 12:43am
Hi,

Could you explain how to differentiate active clients and least active client? Is there any time/ duration ?
Could you paste your SQL code here.
if possible can you post sample data here..

--Praveen G
Praveen Guntuka,
praveen_guntuka@yahoo.com
IP IP Logged
zbumpers
Newbie
Newbie
Avatar

Joined: 13 Oct 2015
Location: United States
Online Status: Offline
Posts: 2
Quote zbumpers Replybullet Posted: 19 Oct 2015 at 7:43am
Time spent with clients are recorded in minutes. I would like Crystal to select each rep and run a separate report for each of them.

Sql Code:
drop table #upper
select top (5)

LAST_NAME
,FIRST_NAME
,msa.CLIENT_ID
,sum(Minutes) As MinutesInvested
,msa.STAFF_ID

,case when msa.STAFF_ID = '5556918' then 'Arron Smith'
when msa.STAFF_ID = '5550166' then 'Kristyn Smith'
       when msa.STAFF_ID = '5521086' then 'Lauren Smith'
       when msa.STAFF_ID= '5554256' then 'John Smith'
      when msa.STAFF_ID= '5556908' then 'Darianna Smith'
     when msa.STAFF_ID = '5559009' then 'William Smith'
     when msa.STAFF_ID = '5555499' then 'Samuel Smith'
     when msa.STAFF_ID = '5557' then 'Nick Smith'
     when msa.STAFF_ID = '5553105' then 'Ryan Smith'
end as Staff_Member

into #upper
from tableOne msa
left join tableTwo dim on msa.CLIENT_ID = dim.CLIENT_ID
--where msa.STAFF_ID in ('5556918','5550166','5521086','5556908','5554256','5559009','5555499','5557','5553105')
where msa.STAFF_ID = '5550166'
AND (SERVICE_DATE > '2015-09-01') AND (SERVICE_DATE < '2015-09-30')

group by msa.CLIENT_ID,STAFF_ID,LAST_NAME,FIRST_NAME
order by MinutesInvested DESC



drop table #lower
SELECT top (5)
LAST_NAME
,FIRST_NAME
,msb.CLIENT_ID
,sum(Minutes) As MinutesInvested
,msb.STAFF_ID

,case when msb.STAFF_ID = '5556918' then 'Arron Smith'
when msb.STAFF_ID = '5550166' then 'Kristyn Smith'
       when msb.STAFF_ID = '5521086' then 'Lauren Smith'
       when msb.STAFF_ID= '5554256' then 'John Smith'
      when msb.STAFF_ID= '5556908' then 'Darianna Smith'
     when msb.STAFF_ID = '5559009' then 'William Smith'
     when msb.STAFF_ID = '5555499' then 'Samuel Smith'
     when msb.STAFF_ID = '5557' then 'Nick Smith'
     when msb.STAFF_ID = '5553105' then 'Ryan Smith'
end as Staff_Member

into #lower
from tableOne msb
left join tableTwo dim on msb.CLIENT_ID = dim.CLIENT_ID
--where msb.STAFF_ID in ('5556918','5550166','5521086','5556908','5554256','5559009','5555499','5557','5553105')
where msb.STAFF_ID = '5550166'
AND (SERVICE_DATE > '2015-09-01') AND (SERVICE_DATE < '2015-09-30')

group by msb.CLIENT_ID,STAFF_ID,LAST_NAME,FIRST_NAME
order by MinutesInvested ASC


select distinct

msa.LAST_NAME
,msa.FIRST_NAME
,msa.CLIENT_ID
,msa.MinutesInvested
,msa.STAFF_ID
,msa.Staff_Member
from #upper msa
Union all
select
msb.LAST_NAME
,msb.FIRST_NAME
,msb.CLIENT_ID
,msb.MinutesInvested
,msb.STAFF_ID
,msb.Staff_Member
from #lower msb


Sql Output:
LAST_NAME     FIRST_NAME     CLIENT_ID     MinutesInvested     STAFF_ID     Staff_Member
CUTHB     Smith     5559637     350     5550166     Kristyn Smith
SHARP     Smith     5555652     230     5550166     Kristyn Smith
STRAHAN     Smith     5555128     420     5550166     Kristyn Smith
SWILLEY     Smith     5552734     330     5550166     Kristyn Smith
WOLFE     Smith     5558029     200     5550166     Kristyn Smith
MARTINE     Smith     5554275     5     5550166     Kristyn Smith
MORGAN     Smith     5554307     5     5550166     Kristyn Smith
BENNETT     Smith     5559611     5     5550166     Kristyn Smith
BENELL     Smith     5554745     5     5550166     Kristyn Smith
PLUMMER     Smith     5558420     5     5550166     Kristyn Smith


IP IP Logged
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.