spLoadSiteSurveyResponses

Parameters

Parameter Parameter Type Mode Description
@SiteSurveysId int IN
@ResponseId int IN
@LoadByIndex bit IN
@ResponseIndex int IN

Definition

Copy


        create procedure dbo.spLoadSiteSurveyResponses(
            @SiteSurveysId    integer,
            @ResponseId        integer,
            @LoadByIndex    bit,
            @ResponseIndex    integer

        )
        as
        begin
            set nocount on
            declare @responses table (Id             integer identity,
                                    ResponseId    integer
            )
            declare @responseCount    integer
            select @responseCount = count(*
            from SiteSurveyResponses
            where SiteSurveysId = @SiteSurveysId

            if (@LoadByIndex = 1)
            begin
                if (@ResponseIndex < 1) set @ResponseIndex = 1
                if (@ResponseIndex > @responseCount) set @ResponseIndex = @responseCount

                insert into @responses(ResponseId)
                select ID from 
                SiteSurveyResponses
                where SiteSurveysId = @SiteSurveysId
                order by ID

                select @ResponseId = ResponseId
                from @responses
                where id = @ResponseIndex
            end

            select a.*, b.LastName, b.FirstName, b.EMail 
            from SiteSurveyResponses a
            left outer join ClientUsers b on a.ClientUsersID = b.ID
            where a.ID = @ResponseId
            and a.SiteSurveysId = @SiteSurveysId

            -- Survey Results
            select a.*, b.SiteSurveyQuestionsId, c.Sequence
            from SiteSurveyResults a
            inner join SiteSurveyAnswers b on a.SiteSurveyAnswersId = b.Id
            inner join SiteSurveyQuestions c on b.SiteSurveyQuestionsid = c.Id
            where SiteSurveyResponsesId = @ResponseId
            order by c.Sequence
        end