I am using SQL Server 2000
and have created a stored procedure so that it can be called in a crystal report, I used the stored procedure to possible speed up the report.
however it still takes an awful long time to run and resource utilisation on the Server (Processor usage) goes sky high while the report is querying the database.
There are other processes running at the same time and other users in the org could be setting off all sorts of other jobs at a similar time, making use of some of the same table I have used in this procedure.
How could I optimise this stored procedure which accepts one parameter, which is a branch name. The parameter (branch name) supplied by the user could vary each time however there are only 28 branches.
The code I used to create the Stored Procedure is given below
Any help or suggestions appreciated
and have created a stored procedure so that it can be called in a crystal report, I used the stored procedure to possible speed up the report.
however it still takes an awful long time to run and resource utilisation on the Server (Processor usage) goes sky high while the report is querying the database.
There are other processes running at the same time and other users in the org could be setting off all sorts of other jobs at a similar time, making use of some of the same table I have used in this procedure.
How could I optimise this stored procedure which accepts one parameter, which is a branch name. The parameter (branch name) supplied by the user could vary each time however there are only 28 branches.
The code I used to create the Stored Procedure is given below
Code:
Create Proc PRS_PortalUser @Branchname varchar(255)
as
Select mem_ref
, mem_id
, mep_id
, Pn_id
, pn_first_name
, Pn_surname
, prole_id
, prod_name as Grade
, pds_name
, pd_status
, mep_status
, br_name
, PD_Start_Date
, PD_End_Date
From pd_scheme
inner join PD on pds_id = pd_pds_id
Inner join membership on PD_mem_id = mem_id
Inner join member_period on Mem_id = Mep_mem_id
Inner join member_location as Grade on Mep_id = mel_mep_id
Inner join member_location as mem_loc on Mep_id = mem_loc.mel_mep_id
Inner join Product on grade.mel_prod_id = prod_id
Inner join person_role on mem_loc.mel_prole_id = prole_id
Inner join person on Prole_person_id = pn_Id
Left Join branch_xref
on mep_id = brxref_record_id
left join branch
on brxref_br_id = br_id
Where pn_id not in (select Pn_id from person
Inner join person_role on pn_id = prole_person_id
Inner join portal_user on prole_id = pu_prole_id)
and pds_name = 'Continuing Professional Development'
and pd_status = '30-Current'
and mep_prod_id = '1-ish'
and left(mep_status, 2) between '02' and '24'
and grade.mel_sy_type = '2'
and grade.mel_current = '1'
and mem_loc.mel_sy_type = '0'
and BR_Name = @branchname
Any help or suggestions appreciated