Stored procedure that runs quickly in SSMS hangs up in SSRS

  • I'm attaching a WORD document that lists the T-SQL code in the stored procedure that runs in SSMS, but gets "stuck" in SSRS.  I don't see the problem.  Most of the stored procedures I write for my reports are similarly written with 1 or more #temp tables and I don't have problems with them.  Any suggestions would be greatly appreciated.

    Thanks

    Attachments:
    You must be logged in to view attached files.
  • Many people here won't open non-text attachments, so here is the code, reformatted courtesy of SQL Prompt:

    USE Live_PTS;
    GO

    /****** Object: StoredProcedure [dbo].[CMS_MakeUP_TIME_11-11-2020] Script Date: 11/17/2020 2:39:36 AM ******/
    SET ANSI_NULLS ON;
    GO

    SET QUOTED_IDENTIFIER ON;
    GO

    ALTER PROCEDURE dbo.[CMS_MakeUP_TIME_11-11-2020]
    --@therapist int,
    --@director int,
    @StartDate DATETIME
    ,@EndDate DATETIME
    ,@District INT
    AS
    BEGIN
    IF OBJECT_ID('tempdb..#billed_caseload') IS NOT NULL
    DROP TABLE #billed_caseload;

    CREATE TABLE #billed_caseload
    (
    Districtid INT
    ,studentid INT
    ,disciplineid INT
    ,individual_time FLOAT
    ,group_time FLOAT -- IEP TIME
    ,consult_time FLOAT
    ,absences FLOAT
    ,unavailable FLOAT
    ,req_ind FLOAT
    ,req_grp FLOAT
    ,req_con FLOAT
    ,ind_freq NVARCHAR(MAX)
    ,grp_freq NVARCHAR(MAX)
    ,consult_freq NVARCHAR(MAX)
    ,curr_status NVARCHAR(MAX)
    ,curr_grade NVARCHAR(11)
    ,curr_schoolid INT
    );

    IF OBJECT_ID('tempdb..#billed ') IS NOT NULL
    DROP TABLE #billed;

    CREATE TABLE #billed
    (
    Districtid INT
    ,studentid INT
    ,disciplineid INT
    ,individual_time FLOAT
    ,group_time FLOAT -- IEP TIME
    ,consult_time FLOAT
    ,absences FLOAT
    ,unavailable FLOAT
    );

    CREATE TABLE #wrkday
    (
    Districtid INT
    ,wrkdays INT,
    );

    DECLARE @thecount AS INT;
    DECLARE @tday AS DATETIME;
    DECLARE @daterng_mnths FLOAT;

    SET @daterng_mnths = DATEDIFF(MONTH, @StartDate, @EndDate);
    SET @thecount = 1;
    SET @tday = GETDATE();

    --set @stdate='20191201'
    DECLARE @nxt AS DATETIME;
    DECLARE @cntwkdy AS INT;
    DECLARE @subtract AS INT;

    SET @nxt = @StartDate;
    SET @cntwkdy = 0;

    WHILE @nxt <= @EndDate
    BEGIN
    IF DATEPART(dw, @nxt) NOT IN ( 1, 7 )
    SET @cntwkdy = @cntwkdy + 1;

    SET @nxt = DATEADD(DAY, 1, @nxt);
    END;

    DECLARE @wrkdays AS INT;

    SET @wrkdays = @cntwkdy -
    (
    SELECT COUNT(*)
    FROM vwrec_target_hour_exceptions
    WHERE district = @District
    AND DATEPART(MONTH, date) = DATEPART(MONTH, @StartDate)
    AND DATEPART(YEAR, date) = DATEPART(YEAR, @EndDate)
    GROUP BY District
    );

    /*
    insert into #wrkday (districtid,wrkdays)
    select id,@cntwkdy from VwRec_Districts where Id=@District--(select DistrictId
    --from
    --VwRecFld_Districts_Directors where DirectorId=@director)

    merge #wrkday as T
    using
    (select district as district,@cntwkdy-count(*) as cnt from vwrec_target_hour_exceptions where DATEPART(month,date)=datepart(month,@StartDate)
    and datepart(year,date)=datepart(year,@EndDate)
    group by District) as S
    on (t.districtid=s.district)
    when matched then
    update set t.wrkdays=s.cnt; */

    /*create a temporary table to store the rows in
    But first drop it if it already exists */
    IF OBJECT_ID('tempdb..#caseload ') IS NOT NULL
    DROP TABLE #caseload;

    CREATE TABLE #caseload
    (
    Districtid INT
    ,studentid INT
    ,curr_schoolid INT
    ,disciplineid INT
    ,curr_status NVARCHAR(MAX)
    ,dob DATETIME
    ,curr_grade NVARCHAR(11)
    ,indfreq NVARCHAR(MAX)
    ,grpfreq NVARCHAR(MAX)
    ,confreq NVARCHAR(MAX)
    ,req_indiv FLOAT
    ,req_grp FLOAT
    ,req_con FLOAT
    ,irf INT
    ,irns FLOAT
    ,irsm FLOAT
    ,ire FLOAT
    ,grf INT
    ,grns FLOAT
    ,grsm FLOAT
    ,gre FLOAT
    ,crf INT
    ,crns FLOAT
    ,crsm FLOAT
    ,cre FLOAT --,
    --prior_status int,
    --Priorst_start_date datetime,
    --priorst_end_date datetime
    );

    CREATE INDEX #temp_index
    ON #caseload (
    Districtid
    ,studentid
    ,disciplineid
    );

    INSERT INTO #caseload
    (
    Districtid
    ,studentid
    ,curr_schoolid
    ,disciplineid
    ,curr_status
    ,dob
    ,curr_grade
    ,indfreq
    ,grpfreq
    ,confreq
    ,req_indiv
    ,req_grp
    ,req_con
    ,irf
    ,irns
    ,irsm
    ,ire
    ,grf
    ,grns
    ,grsm
    ,gre
    ,crf
    ,crns
    ,crsm
    ,cre
    ) --,prior_status,Priorst_start_date,priorst_end_date)
    SELECT DISTINCT
    k.district
    ,b.student
    ,a.Current_School
    ,b.therapy_type
    ,g.name
    ,a.Date_of_Birth
    ,c.Name
    ,'(' + CAST(b.Individual_Repeats_Number_of_Sessions AS VARCHAR(3)) + ') '
    + CAST(b.Individual_Repeats_Session_Minutes AS VARCHAR(20)) + ' minutes session(s) every '
    + CAST(b.individual_repeats_every AS VARCHAR(3)) + ' ' + h.Noun
    ,'(' + CAST(b.Group_Repeats_Number_of_Sessions AS VARCHAR(3)) + ') '
    + CAST(b.Group_Repeats_Session_Minutes AS VARCHAR(20)) + ' minutes session(s) every '
    + CAST(b.Group_Repeats_Every AS VARCHAR(3)) + ' ' + i.Noun
    ,'(' + CAST(b.Consult_Repeats_Number_of_Sessions AS VARCHAR(3)) + ') '
    + CAST(b.Consult_Repeats_Session_Minutes AS VARCHAR(20)) + ' minutes session(s) every '
    + CAST(b.Consult_Repeats_Every AS VARCHAR(3)) + ' ' + j.Noun
    ,CASE b.individual_repeat_frequency
    WHEN 492 THEN
    (((b.Individual_Repeats_Number_of_Sessions * b.Individual_Repeats_Session_Minutes)
    * (CAST(@wrkdays AS FLOAT) / CAST(k.Days_in_Cycle AS FLOAT))
    * (1 / (CASE
    WHEN b.Individual_Repeats_Every = 0 THEN
    1
    ELSE
    b.Individual_Repeats_Every
    END
    )
    )
    ) / 60
    ) * @daterng_mnths
    WHEN 491 THEN
    (((b.Individual_Repeats_Number_of_Sessions * b.Individual_Repeats_Session_Minutes) * (.1)
    * (1 / (CASE
    WHEN b.Individual_Repeats_Every = 0 THEN
    1
    ELSE
    b.Individual_Repeats_Every
    END
    )
    )
    ) / 60
    ) * @daterng_mnths
    WHEN 80 THEN
    (((b.Individual_Repeats_Number_of_Sessions * b.Individual_Repeats_Session_Minutes) * (4)
    * (1 / (CASE
    WHEN b.Individual_Repeats_Every = 0 THEN
    1
    ELSE
    b.Individual_Repeats_Every
    END
    )
    )
    ) / 60
    ) * @daterng_mnths
    WHEN 81 THEN
    (((b.Individual_Repeats_Number_of_Sessions * b.Individual_Repeats_Session_Minutes) * (1)
    * (1 / (CASE
    WHEN b.Individual_Repeats_Every = 0 THEN
    1
    ELSE
    b.Individual_Repeats_Every
    END
    )
    )
    ) / 60
    ) * @daterng_mnths
    WHEN 489 THEN
    (((b.Individual_Repeats_Number_of_Sessions * b.Individual_Repeats_Session_Minutes) * (@wrkdays)
    * (1 / (CASE
    WHEN b.Individual_Repeats_Every = 0 THEN
    1
    ELSE
    b.Individual_Repeats_Every
    END
    )
    )
    ) / 60
    ) * @daterng_mnths
    WHEN 490 THEN
    (((b.Individual_Repeats_Number_of_Sessions * b.Individual_Repeats_Session_Minutes) * (.4)
    * (1 / (CASE
    WHEN b.Individual_Repeats_Every = 0 THEN
    1
    ELSE
    b.Individual_Repeats_Every
    END
    )
    )
    ) / 60
    ) * @daterng_mnths
    WHEN 493 THEN
    0
    ELSE
    0
    END
    ,CASE b.group_repeat_frequency
    WHEN 492 THEN
    (((b.group_Repeats_Number_of_Sessions * b.group_Repeats_Session_Minutes)
    * (CAST(@wrkdays AS FLOAT) / CAST(k.Days_in_Cycle AS FLOAT)) * (1 / (CASE
    WHEN b.Group_Repeats_Every = 0 THEN
    1
    ELSE
    b.Group_Repeats_Every
    END
    )
    )
    ) / 60
    ) * @daterng_mnths
    WHEN 491 THEN
    (((b.Group_Repeats_Number_of_Sessions * b.Group_Repeats_Session_Minutes) * (.1)
    * (1 / (CASE
    WHEN b.group_Repeats_Every = 0 THEN
    1
    ELSE
    b.Group_Repeats_Every
    END
    )
    )
    ) / 60
    ) * @daterng_mnths
    WHEN 80 THEN
    (((b.Group_Repeats_Number_of_Sessions * b.Group_Repeats_Session_Minutes) * (4)
    * (1 / (CASE
    WHEN b.Group_Repeats_Every = 0 THEN
    1
    ELSE
    b.Group_Repeats_Every
    END
    )
    )
    ) / 60
    ) * @daterng_mnths
    WHEN 81 THEN
    (((b.Group_Repeats_Number_of_Sessions * b.Group_Repeats_Session_Minutes) * (1)
    * (1 / (CASE
    WHEN b.Group_Repeats_Every = 0 THEN
    1
    ELSE
    b.Group_Repeats_Every
    END
    )
    )
    ) / 60
    ) * @daterng_mnths
    WHEN 489 THEN
    (((b.Group_Repeats_Number_of_Sessions * b.Group_Repeats_Session_Minutes) * (@wrkdays)
    * (1 / (CASE
    WHEN b.Group_Repeats_Every = 0 THEN
    1
    ELSE
    b.Group_Repeats_Every
    END
    )
    )
    ) / 60
    ) * @daterng_mnths
    WHEN 490 THEN
    (((b.Group_Repeats_Number_of_Sessions * b.Group_Repeats_Session_Minutes) * (.4)
    * (1 / (CASE
    WHEN b.Group_Repeats_Every = 0 THEN
    1
    ELSE
    b.Group_Repeats_Every
    END
    )
    )
    ) / 60
    ) * @daterng_mnths
    WHEN 493 THEN
    0
    ELSE
    0
    END
    ,CASE b.Consult_Repeat_Frequency
    WHEN 492 THEN
    (((b.Consult_Repeats_Number_of_Sessions * b.Consult_Repeats_Session_Minutes)
    * (CAST(@wrkdays AS FLOAT) / CAST(k.Days_in_Cycle AS FLOAT)) * (1 / (CASE
    WHEN b.Consult_Repeats_Every = 0 THEN
    1
    ELSE
    b.Consult_Repeats_Every
    END
    )
    )
    ) / 60
    ) * @daterng_mnths
    WHEN 491 THEN
    (((b.Consult_Repeats_Number_of_Sessions * b.Consult_Repeats_Session_Minutes) * (.1)
    * (1 / (CASE
    WHEN b.Consult_Repeats_Every = 0 THEN
    1
    ELSE
    b.Consult_Repeats_Every
    END
    )
    )
    ) / 60
    ) * @daterng_mnths
    WHEN 80 THEN
    (((b.Consult_Repeats_Number_of_Sessions * b.Consult_Repeats_Session_Minutes) * (4)
    * (1 / (CASE
    WHEN b.Consult_Repeats_Every = 0 THEN
    1
    ELSE
    b.Consult_Repeats_Every
    END
    )
    )
    ) / 60
    ) * @daterng_mnths
    WHEN 81 THEN
    (((b.Consult_Repeats_Number_of_Sessions * b.Consult_Repeats_Session_Minutes) * (1)
    * (1 / (CASE
    WHEN b.Consult_Repeats_Every = 0 THEN
    1
    ELSE
    b.Consult_Repeat_Frequency
    END
    )
    )
    ) / 60
    ) * @daterng_mnths
    WHEN 489 THEN
    (((b.Consult_Repeats_Number_of_Sessions * b.Consult_Repeats_Session_Minutes) * (@wrkdays)
    * (1 / (CASE
    WHEN b.Consult_Repeats_Every = 0 THEN
    1
    ELSE
    b.Consult_Repeats_Every
    END
    )
    )
    ) / 60
    ) * @daterng_mnths
    WHEN 490 THEN
    (((b.Consult_Repeats_Number_of_Sessions * b.Consult_Repeats_Session_Minutes) * (.4)
    * (1 / (CASE
    WHEN b.Consult_Repeats_Every = 0 THEN
    1
    ELSE
    b.Consult_Repeats_Every
    END
    )
    )
    ) / 60
    ) * @daterng_mnths
    WHEN 493 THEN
    0
    ELSE
    0
    END
    ,b.individual_repeat_frequency
    ,b.Individual_Repeats_Number_of_Sessions
    ,b.Individual_Repeats_Session_Minutes
    ,b.Individual_Repeats_Every
    ,b.Group_Repeat_Frequency
    ,b.Group_Repeats_Number_of_Sessions
    ,b.Group_Repeats_Session_Minutes
    ,b.Group_Repeats_Every
    ,b.Consult_Repeat_Frequency
    ,b.Consult_Repeats_Number_of_Sessions
    ,b.Consult_Repeats_Session_Minutes
    ,b.Consult_Repeats_Every --,
    --p.Student_Status,p.Start_Date,p.End_Date
    FROM vwrec_student_therapies b
    LEFT JOIN VwRec_Students a
    ON b.student = a.id
    LEFT JOIN VwRec_Student_Grades c
    ON a.Grade = c.Id
    LEFT JOIN
    --VwRec_Therapists d on b.Primary_Therapist=d.Id left join
    --VwRec_Therapy_Types f on d.Therapy_Type=f.Id left join
    VwRec_Student_Statuses g
    ON b.Current_Student_Status = g.Id
    LEFT JOIN VwRec_Student_Treatment_Frequencies h
    ON b.Individual_Repeat_Frequency = h.Id
    LEFT JOIN VwRec_Student_Treatment_Frequencies i
    ON b.Group_Repeat_Frequency = i.Id
    LEFT JOIN VwRec_Student_Treatment_Frequencies j
    ON b.Consult_Repeat_Frequency = j.Id
    LEFT JOIN VwRec_Schools k
    ON a.Current_School = k.Id
    LEFT JOIN VwRec_Student_Therapy_Statuses p
    ON b.id = p.Student_Therapy
    WHERE (
    a.Lock_Student IS NULL
    OR a.Lock_Student = 0
    )
    AND k.District = @District
    AND
    (
    p.Student_Status = 78
    AND
    (
    (
    p.Start_Date <= @StartDate
    AND p.End_Date IS NULL
    )
    OR
    (
    p.Start_Date <= @StartDate
    AND p.End_Date >= @EndDate
    )
    OR (p.Start_Date
    BETWEEN @StartDate AND @EndDate
    )
    )
    );

    INSERT INTO #billed -- INDIVIDUAL TIME
    (
    Districtid
    ,studentid
    ,disciplineid
    ,individual_time
    ,group_time
    ,consult_time
    ,absences
    ,unavailable
    )
    SELECT b.District_id
    ,b.student_id
    ,c.Therapy_Type
    ,SUM(CAST(b.minutes AS FLOAT)) / 60
    ,0
    ,0
    ,0
    ,0
    FROM PTS_student_time_entry b
    LEFT JOIN VwRec_Therapists c
    ON b.Therapist_id = c.id
    WHERE b.Date
    BETWEEN @StartDate AND @EndDate
    AND b.student_time_entry_type_id = 141
    AND b.district_id = @District -- in (select districtid from VwRecFld_Districts_Directors where DirectorId=@director)
    GROUP BY b.District_id
    ,b.student_id
    ,c.Therapy_Type;

    MERGE #billed T
    USING
    (
    SELECT districtid = b.district_id
    ,disciplineid = c.therapy_type
    ,studentid = b.student_id
    ,hours = SUM(CAST(b.minutes AS FLOAT)) / 60
    FROM PTS_student_time_entry b
    LEFT JOIN VwRec_Therapists c
    ON b.Therapist_id = c.id
    WHERE b.Date
    BETWEEN @StartDate AND @EndDate
    AND b.student_time_entry_type_id = 138
    AND b.district_id = @District -- in(select districtid from VwRecFld_Districts_Directors where DirectorId=@director) --CONSULT TIME
    GROUP BY b.district_id
    ,c.therapy_type
    ,b.student_id
    ) S
    ON (
    T.studentid = S.studentid
    AND T.Districtid = S.Districtid
    AND T.disciplineid = S.disciplineid
    )
    WHEN MATCHED THEN
    UPDATE SET T.consult_time = S.hours
    WHEN NOT MATCHED THEN
    INSERT
    (
    Districtid
    ,studentid
    ,disciplineid
    ,individual_time
    ,group_time
    ,consult_time
    ,absences
    ,unavailable
    )
    VALUES
    (S.districtid, S.studentid, S.disciplineid, 0, 0, S.hours, 0, 0);

    MERGE #billed T
    USING
    (
    SELECT districtid = b.district_id
    ,disciplineid = c.therapy_type
    ,studentid = a.student_id
    ,hours = SUM(CAST(b.minutes AS FLOAT)) / 60
    FROM PTS_group_time_entry b
    LEFT JOIN pts_group_Time_entry_student a
    ON b.id = a.entry_id
    LEFT JOIN VwRec_Therapists c
    ON b.Therapist_id = c.id
    WHERE b.Date
    BETWEEN @StartDate AND @EndDate
    AND b.district_id = @District -- in(select districtid from VwRecFld_Districts_Directors where DirectorId=@director) --CONSULT TIME
    GROUP BY b.district_id
    ,c.therapy_type
    ,a.student_id
    ) S
    ON (
    T.studentid = S.studentid
    AND T.Districtid = S.Districtid
    AND T.disciplineid = S.disciplineid
    )
    WHEN MATCHED THEN
    UPDATE SET T.group_time = S.hours
    WHEN NOT MATCHED THEN
    INSERT
    (
    Districtid
    ,studentid
    ,disciplineid
    ,individual_time
    ,group_time
    ,consult_time
    ,absences
    ,unavailable
    )
    VALUES
    (S.districtid, S.studentid, S.disciplineid, 0, S.hours, 0, 0, 0);

    MERGE #billed T
    USING
    (
    SELECT districtid = b.district_id
    ,disciplineid = c.therapy_type
    ,studentid = b.student_id
    ,hours = COUNT(*)
    FROM PTS_student_absent b
    LEFT JOIN VwRec_Therapists c
    ON b.Therapist_id = c.id
    WHERE b.Date
    BETWEEN @StartDate AND @EndDate
    AND b.district_id = @District
    GROUP BY b.district_id
    ,c.therapy_type
    ,b.student_id
    ) S
    ON (
    T.studentid = S.studentid
    AND T.Districtid = S.Districtid
    AND T.disciplineid = S.disciplineid
    )
    WHEN MATCHED THEN
    UPDATE SET T.consult_time = S.hours
    WHEN NOT MATCHED THEN
    INSERT
    (
    Districtid
    ,studentid
    ,disciplineid
    ,individual_time
    ,group_time
    ,consult_time
    ,absences
    ,unavailable
    )
    VALUES
    (S.districtid, S.studentid, S.disciplineid, 0, 0, 0, S.hours, 0);

    MERGE #billed T
    USING
    (
    SELECT districtid = b.district_id
    ,disciplineid = c.therapy_type
    ,studentid = b.student_id
    ,hours = COUNT(*)
    FROM PTS_student_unavailable b
    LEFT JOIN VwRec_Therapists c
    ON b.Therapist_id = c.id
    WHERE b.Date
    BETWEEN @StartDate AND @EndDate
    AND b.district_id = @District
    GROUP BY b.district_id
    ,c.therapy_type
    ,b.student_id
    ) S
    ON (
    T.studentid = S.studentid
    AND T.Districtid = S.Districtid
    AND T.disciplineid = S.disciplineid
    )
    WHEN MATCHED THEN
    UPDATE SET T.consult_time = S.hours
    WHEN NOT MATCHED THEN
    INSERT
    (
    Districtid
    ,studentid
    ,disciplineid
    ,individual_time
    ,group_time
    ,consult_time
    ,absences
    ,unavailable
    )
    VALUES
    (S.districtid, S.studentid, S.disciplineid, 0, 0, 0, 0, S.hours);

    INSERT INTO #billed_caseload
    (
    Districtid
    ,studentid
    ,disciplineid
    ,individual_time
    ,group_time
    ,consult_time
    ,absences
    ,unavailable
    ,req_ind
    ,req_grp
    ,req_con
    ,ind_freq
    ,grp_freq
    ,consult_freq
    ,curr_status
    ,curr_grade
    ,curr_schoolid
    )
    SELECT Districtid
    ,studentid
    ,disciplineid
    ,individual_time
    ,group_time
    ,consult_time
    ,absences
    ,unavailable
    ,0
    ,0
    ,0
    ,''
    ,''
    ,''
    ,''
    ,''
    ,0
    FROM #billed;

    MERGE #billed_caseload T
    USING
    (
    SELECT districtid = Districtid
    ,studentid = studentid
    ,disciplineid = disciplineid
    ,indfreq = indfreq
    ,grpfreq = grpfreq
    ,confreq = confreq
    ,reqind = req_indiv
    ,reqgrp = req_grp
    ,reqcon = req_con
    ,currschoolid = curr_schoolid
    ,currgrade = curr_grade
    ,currstatus = curr_status --,prior_status as pstatus,
    --Priorst_start_date as pstatusSD,priorst_end_date as pstatusED
    FROM #caseload
    ) S
    ON (
    T.Districtid = S.districtid
    AND T.studentid = S.studentid
    AND T.disciplineid = S.disciplineid
    )
    WHEN MATCHED THEN
    UPDATE SET T.req_ind = S.reqind
    ,T.req_grp = S.reqgrp
    ,T.req_con = S.reqcon
    ,T.ind_freq = S.indfreq
    ,T.grp_freq = S.grpfreq
    ,T.consult_freq = S.confreq
    ,T.curr_status = S.currstatus
    ,T.curr_grade = S.currgrade
    ,T.curr_schoolid = S.currschoolid
    WHEN NOT MATCHED THEN
    INSERT
    (
    Districtid
    ,studentid
    ,disciplineid
    ,individual_time
    ,group_time
    ,consult_time
    ,absences
    ,unavailable
    ,req_ind
    ,req_grp
    ,req_con
    ,ind_freq
    ,grp_freq
    ,consult_freq
    ,curr_status
    ,curr_grade
    ,curr_schoolid
    )
    VALUES
    (S.districtid, S.studentid, S.disciplineid, 0, 0, 0, 0, 0, S.reqind, S.reqgrp, S.reqcon, S.indfreq, S.grpfreq
    ,S.confreq, S.currstatus, S.currgrade, S.currschoolid);

    SELECT District = b.District_Name
    ,Discipline = c.name
    ,Studentid = a.studentid
    ,Student = d.Last_Name + ', ' + d.First_Name
    ,DOB = d.Date_of_Birth
    ,AddedOn = d.Date_and_Time_Added
    ,CurrentGrade = a.curr_grade
    ,CurrentStatus = CASE
    WHEN a.curr_status IS NULL THEN
    k.Name
    ELSE
    a.curr_status
    END
    ,CurrentSchool = e.School_Name
    ,CURR_IndividualFrequency = a.ind_freq
    ,IndividualRequired = a.req_ind
    ,IndividualDelivered = a.individual_time
    ,CURR_GroupFrequency = a.grp_freq
    ,GroupRequired = a.req_grp
    ,IEPGroupDelivered = a.group_time
    ,CURR_ConsultFrequency = a.consult_freq
    ,ConsultRequired = a.req_con
    ,ConsultDelivered = a.consult_time
    ,AbsencesReported = a.absences
    ,UnavailableReported = a.unavailable
    ,IndividualOwed = a.req_ind - a.individual_time
    ,GroupOwed = a.req_grp - a.group_time
    ,ConsultOwed = a.req_con - a.consult_time
    ,Current_Primary_Therapist = h.last_name + ', ' + h.first_name
    FROM #billed_caseload a
    LEFT JOIN vwrec_districts b
    ON a.Districtid = b.id
    LEFT JOIN VwRec_Therapy_Types c
    ON a.disciplineid = c.id
    LEFT JOIN vwrec_students d
    ON a.studentid = d.id
    LEFT JOIN vwrec_schools e
    ON a.curr_schoolid = e.Id
    LEFT JOIN VwRec_Student_Therapies f
    ON (
    a.studentid = f.Student
    AND a.disciplineid = f.therapy_type
    )
    LEFT JOIN vwrec_therapists g
    ON (f.Primary_Therapist = g.id)
    LEFT JOIN core_c_m_s_user h
    ON g.CMS_User = h.id
    LEFT JOIN VwRec_Student_Statuses k
    ON f.Current_Student_Status = k.Id
    WHERE f.Primary_Therapist IS NOT NULL;

    --select * from #wrkday
    SELECT *
    FROM #caseload;

    SELECT *
    FROM #billed;

    SELECT @StartDate
    ,@EndDate
    ,@wrkdays
    ,@daterng_mnths;
    END;

    The absence of evidence is not evidence of absence
    - Martin Rees
    The absence of consumable DDL, sample data and desired results is, however, evidence of the absence of my response
    - Phil Parkin

  • That is a lot of code - personally I would refactor this to a single query using either CTE's or CROSS/OUTER APPLY where I could.  As to your problem...it is almost certainly due to returning 3 separate result sets to SSRS - where it is expecting a single result set to be mapped to a single data set.

    Jeffrey Williams
    “We are all faced with a series of great opportunities brilliantly disguised as impossible situations.”

    ― Charles R. Swindoll

    How to post questions to get better answers faster
    Managing Transaction Logs

  • I removed the 2 select statements at the end of the stored procedure and that solved the problem - Last Month.

    The problem is happening again after I added another Dataset (and a table in the report body using the second dataset) to the report.

    I removed the second table and dataset and the problem is still happening - I don't know what to do now.   The Directors were really like this report too.

  • Not much for us to go on - not sure how to help diagnose a problem when I cannot see the problem.  As a guess - whatever you added is now causing issues and it hasn't actually been removed.

    Jeffrey Williams
    “We are all faced with a series of great opportunities brilliantly disguised as impossible situations.”

    ― Charles R. Swindoll

    How to post questions to get better answers faster
    Managing Transaction Logs

Viewing 5 posts - 1 through 4 (of 4 total)

You must be logged in to reply to this topic. Login to reply