Tuesday, February 28, 2012

SQL(Careate Function)



CREATE FUNCTION dbo.Portal_fnGetRestaurantRating (@CustomerId bigint)
RETURNS int
AS
BEGIN
      DECLARE
            @value int

SELECT @value = IsNull(SUM(Rating) / Count(Rating), 1) FROM    Portal_CustomerReview
      WHERE CustomerId = @CustomerId

      RETURN @value
END

--Call the function
SELECT dbo.Portal_fnGetRestaurantRating(8)

No comments:

Post a Comment