SET ANSI_NULLS ON GO SET QUOTED_IDENTIFIER ON GO -- ============================================= -- Author: Keith -- Create date: October 2, 2006 -- Description: When the user rates the other user it is inserted into the -- UserRating table then the total of all the columns for that row is then -- added to the Users table RateTotal and the total of the all the columns -- and divided it by the number of rows found and update it to the RateAverage -- and get the number of RateTimes of all the rows -- ============================================= CREATE PROCEDURE UsersRating (@RateTimes int, @RateAverage float, @RateTotals bigint, @UserID int, @Giver varchar, @Rate int) AS BEGIN DECLARE @Average float DECLARE @Total int DECLARE @Times int SET @Total = SELECT SUM(Rate) FROM UsersRating WHERE UserID = @UserID SET @Average = SELECT SUM(Rate)/ COUNT(Rate) FROM UsersRating WHERE UserID = @UserID SET @Times = SELECT COUNT(Rate) FROM UserRatings WHERE UserID = @UserID SELECT UserRating.UserID, Users.UserID, Giver, Rate, RateTimes, RateAverage, RateTotals FROM UserRating JOIN Users ON UserRating.UserID = Users.UserID UPDATE UserRating SET UserID = @UserID, Giver = @Giver, Rating = @Rate UPDATE Users SET RateAverage = @Average, RateTimes = @Times, RateTotals = @RateTotals END GO