• HI Joel,

    I tried the suggestions that you offered. I tried to incorporate the @TotalVotes count as a subselect but I keep getting errors. So I came up with the following:

    I cast the VotePercentage as int because I have to pass it back to a js function in order to display it. Do I need to have to seperate selects in order to display the count @TotalVotes or can incorporate this somehow into the main query?

    declare @Gender varchar(20)

    set @Gender = 'female'

    DECLARE @TotalVotes int

    SELECT @TotalVotes = SUM(CASE WHEN VoteFor = 1 THEN 1

    WHEN VoteAgainst = 1 THEN -1

    ELSE 0

    END)

    from dbo.tblPresenters a

    left outer JOIN dbo.tblCompWeek_02 pr

    ON a.PresenterID = pr.PresenterID

    WHERE PresenterGender=@Gender

    select

    a.PresenterID,

    a.presenterName,

    a.PresenterGender,

    SUM(CASE WHEN isnull(VoteFor,0) = 1 THEN 1 ELSE 0 END) AS NumVoteFor,

    SUM(CASE WHEN isnull(VoteAgainst,0) = 1 THEN 1 ELSE 0 END) AS NumVoteAgainst,

    cast(SUM(CASE WHEN VoteFor = 1 THEN 1 WHEN VoteAgainst = 1 THEN -1 ELSE 0 END)* 100 / @TotalVotes as int) as VotePercentage

    from dbo.tblPresenters a

    left outer JOIN dbo.tblCompWeek_02 pr

    ON a.PresenterID = pr.PresenterID

    WHERE PresenterGender=@Gender

    group by a.PresenterID,pr.PresenterID,a.presenterName,a.PresenterGender

    8Jackiefemale 0 0 0

    10Meganfemale 0 0 0

    11Alexandrafemale 3 1 33

    12Mimifemale 0 0 0

    14Youshafemale 0 0 0

    15Angelafemale 5 1 66

    18Karafemale 0 0 0