spNetAccountRelation_FriendCounts

Parameters

Parameter Parameter Type Mode Description
@NetAccountID int IN

Definition

Copy


        CREATE PROCEDURE [dbo].[spNetAccountRelation_FriendCounts]
            (
            @NetAccountID int
            )
            AS

            BEGIN

            DECLARE @Friends int
            DECLARE @FriendRequests int
            DECLARE @PendingRequests int

            SELECT @Friends  = Count(ID) FROM 
            (
            SELECT a.ID
            FROM [NetAccountRelation] a
            INNER JOIN [NetAccount] n on n.ID = a.RelationAccountID
            WHERE
            a.NetAccountID = @NetAccountID 
            AND 
            (a.BlockedID = 0 OR a.BlockedID IS NULL)
            AND
            a.Confirmation > 0
            AND
            n.Deleted = 0

            UNION

            SELECT b.ID
            FROM [NetAccountRelation] b
            INNER JOIN [NetAccount] n on n.ID = b.NetAccountID
            WHERE
            b.RelationAccountID = @NetAccountID 
            AND 
            (b.BlockedID = 0 OR b.BlockedID IS NULL)
            AND
            b.Confirmation > 0
            AND
            n.Deleted = 0
            ) AS x


            SELECT @FriendRequests = Count(r.ID)
            FROM [NetAccountRelation] r
            INNER JOIN [NetAccount] n on n.ID = r.NetAccountID
            WHERE
            RelationAccountID = @NetAccountID 
            AND 
            (BlockedID = 0 OR BlockedID IS NULL)
            AND
            Confirmation = 0
            AND
            Deleted = 0


            SELECT @PendingRequests = Count(r.ID)
            FROM [NetAccountRelation] r 
            INNER JOIN [NetAccount] n on n.ID = r.RelationAccountID
            WHERE
            NetAccountID = @NetAccountID 
            AND 
            (BlockedID = 0 OR BlockedID IS NULL)
            AND
            Confirmation = 0
            AND
            n.Deleted = 0

            SELECT ISNULL(@Friends,0) 'Friends', ISNULL(@FriendRequests,0) 'FriendRequests', ISNULL(@PendingRequests,0) 'PendingRequests'

            END