Hi this is my tables structure :
and this is my stored procedure :
GO
ALTER PROCEDURE [dbo].[uspGetVote](@TeamID INT,@CardID INT)
AS
BEGIN
select cast(avg(VoteValue) as float) as [AverageVoteValue] from Vote where datediff(day,getdate(),LastModifiedDateTime) <= 7 and TeamID = @TeamID and CardID=@CardID Group By TeamID,CardID order by AverageVoteValue
END
ALTER PROCEDURE [dbo].[uspGetVote](@TeamID INT,@CardID INT)
AS
BEGIN
select cast(avg(VoteValue) as float) as [AverageVoteValue] from Vote where datediff(day,getdate(),LastModifiedDateTime) <= 7 and TeamID = @TeamID and CardID=@CardID Group By TeamID,CardID order by AverageVoteValue
END
i want to join VoteComment Table also please give me a query for that
thank you


Upendra Pratap ShahiRank #329 · 7.5K reputationPosted Sep 3, 2015, 2:56 AM EDT
select cast(avg(VoteValue) as float) as [AverageVoteValue] from Vote inner join VoteComment on Vote.VoteId=VoteComment.VoteId where datediff(day,getdate(),LastModifiedDateTime) <= 7
and TeamID = @TeamID and CardID=@CardID Group By TeamID,CardID order by AverageVoteValue
SivakumarRank #2,827 · 503 reputationPosted Sep 3, 2015, 3:53 AM EDT
Column 'VoteComment.Comment' is invalid in the select list because it is not contained in either an aggregate function or the GROUP BY clause.
this is a procedure :
ALTER PROCEDURE [dbo].[uspGetVote](@TeamID INT,@CardID INT)
AS
BEGIN
select Comment,cast(avg(VoteValue) as decimal(8,2))as [AverageVoteValue] ,Comment from Vote inner join VoteComment on Vote.VoteId=VoteComment.VoteId where datediff(day,getdate(),LastModifiedDateTime) <= 7
and TeamID = @TeamID and CardID=@CardID Group By TeamID,CardID order by AverageVoteValue
END
SivakumarRank #2,827 · 503 reputationPosted Sep 3, 2015, 4:09 AM EDT