All pastes #190008 Raw Edit

Shin-Ra

public sql v1 · immutable
·published 2006-10-03 16:56 UTC
rendered paste body
set ANSI_NULLS ONset 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-- =============================================ALTER PROCEDURE [dbo].[UsersRating] (@UserID int,@Giver varchar,@Rate int)ASBEGIN	DECLARE @Total int	DECLARE @Average varchar	DECLARE @Times int	SELECT @Total = SUM(Rate) FROM UserRating WHERE UserID = @UserID	SELECT @Average = SUM(Rate)/COUNT(Rate)  FROM UserRating WHERE UserID = @UserID	SELECT @Times = COUNT(Rate) FROM UserRating WHERE UserID = @UserID	SELECT UserRating.UserID, Users.UserID, Giver, Rate, RateTimes, RateAverage, 		   RateTotals	FROM UserRating INNER JOIN Users	ON UserRating.UserID = Users.UserID	INSERT INTO UserRating(UserID, Giver, Rate) VALUES(@UserID, @Giver, @Rate)	UPDATE Users SET RateAverage = @Average, RateTimes = @Times, 		   RateTotals = @Total WHERE UserID = @UserIDEND