我正在使用以下脚本来尝试计算从您上次访问组到现在在我们系统上的组中创建的新评论和新讨论的数量。我已经写了以下内容,但无法正常工作:
SELECT TOP(6) a.GroupID , a. GroupName, sbuser.sf_NewGroupActivity( a.GroupID ,b.LastVisited) AS NumberUpdates
FROM Groups a
INNER JOIN GroupMembers b ON b .GroupID = a.GroupID
WHERE b. MemberID = 102
GROUP BY a.GroupID , a.GroupName, b.LastVisited
ORDER BY NumberUpdates ASC
sf脚本如下:
RETURNS INT
AS
BEGIN
DECLARE @OUTSTR INT
DECLARE @OUT1 INT
DECLARE @OUT2 INT
SET @OUT1 = (SELECT CAST(COUNT(GroupDiscussionsID) AS INT) FROM GroupDiscussions
WHERE MemberID = @GroupID AND CreateDate BETWEEN @LastVisited AND GetDate())
SET @OUT2 = (SELECT CAST(COUNT(GroupCommentID) AS INT) FROM GroupComments
WHERE MemberID = @GroupID AND CreateDate BETWEEN @LastVisited AND GetDate())
SET @OUTSTR = @OUT1 + @OUT2
RETURN @OUTSTR
END
我不知道如何让这个列出按更新数量排序的前 6 个更新组。任何想法、建议或解决方案将不胜感激。非常感谢
新杰克