set ANSI_NULLS ON set QUOTED_IDENTIFIER ON go -- ============================================= -- Author: Keith Rusler -- 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 -- ============================================= ALTER PROCEDURE [dbo].[UsersRating] (@UserID int, @Giver varchar, @Rate int) AS BEGIN INSERT INTO UserRating(UserID, Giver, Rate) VALUES(@UserID, @Giver, @Rate) DECLARE @Total int DECLARE @Average float DECLARE @Times int SELECT @Total = SUM(Rate), @Times = COUNT(Rate) FROM UserRating WHERE UserID = @UserID SET @Average = @Total / @Times UPDATE Users SET RateAverage = @Average, RateTimes = @Times, RateTotals = @Total WHERE UserID = @UserID END