All pastes #188902 Raw Edit

Shin-Ra

public sql v1 · immutable
·published 2006-10-02 17:03 UTC
rendered paste body
SET ANSI_NULLS ONGOSET QUOTED_IDENTIFIER ONGO-- =============================================-- 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)ASBEGIN	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	ENDGO