cs_Folder_GetFolders///cs_Folder_GetSummary///cs_Folder_MoveFolder

本文介绍了一个SQL Server存储过程,用于移动文件夹并获取指定用户的博客汇总信息。其中包括按评论数量排序的最活跃博客文章及未读文章数量等。此过程还涉及复杂的联表查询和临时表操作。
ContractedBlock.gifExpandedBlockStart.gifcs_Folder_MoveFolder
None.gifALTER  PROC [dbo].cs_Folder_MoveFolder
None.gif    
@FolderId INT,
None.gif    
@NewParentFolderId INT = NULL
None.gif
AS
ExpandedBlockStart.gifContractedBlock.gif
/**//*更新那个ParentFolderId*/
None.gif
UPDATE cs_Folder
None.gif
SET ParentFolderId = @NewParentFolderId
None.gif
WHERE FolderId = @FolderId
None.gif
ContractedBlock.gifExpandedBlockStart.gifcs_Folder_GetSummary
None.gifALTER  PROC [dbo].cs_Folder_GetSummary
None.gif    
@UserId INT,
None.gif    
@SettingsID INT,
None.gif    
@FolderId INT = NULL
None.gif
None.gif
AS
None.gif
BEGIN
None.gif
None.gif
IF (@FolderId IS NULL)
None.gif
BEGIN
None.gif    
SET @FolderId = -1
None.gif
END
None.gif
None.gif
-- Give me the top 10 most active blog posts
None.gif--
获取前10条最活跃的博客(应该是显示显示在主页上的吧)
None.gif
SELECT     TOP 10
None.gif    fp.FeedPostId,
None.gif    fp.FeedId,
None.gif    fp.Author,
None.gif    fp.Title,
None.gif    fp.Description,
None.gif    fp.Source,
None.gif    fp.GuidName,
None.gif    fp.GuidIsPermaLink,
None.gif    fp.Link,
None.gif    fp.PubDate,
None.gif    fp.CommentsUrl,
None.gif    fp.EnclosureUrl,
None.gif    fp.EnclosureLength,
None.gif    fp.EnclosureType,
None.gif    fp.Creator,
None.gif    fp.CommentApiUrl,
None.gif    fp.CommentRssUrl,
None.gif    fp.CommentCount
None.gif
FROM     cs_Feed f,
None.gif    cs_FeedPost fp,
None.gif    cs_FolderFeed ff
None.gif
WHERE f.FeedId = fp.FeedId
None.gif  
AND fp.PubDate >= DATEADD(day-15GetDate())
None.gif  
AND f.FeedId = ff.FeedId
None.gif  
AND ff.UserId = @UserId
None.gif  
AND IsNull(ff.FolderId,-1= @FolderId
None.gif  
AND f.SettingsID = @SettingsID AND ff.SettingsID = @SettingsID
None.gif  
ORDER BY fp.CommentCount DESC
None.gif
None.gif
None.gif
None.gif
SELECT top 100     fp.FeedPostId,
None.gif    fp.FeedId,
None.gif    fp.Author,
None.gif    fp.Title,
None.gif    fp.Description,
None.gif    fp.Source,
None.gif    fp.GuidName,
None.gif    fp.GuidIsPermaLink,
None.gif    fp.Link,
None.gif    fp.PubDate,
None.gif    fp.CommentsUrl,
None.gif    fp.EnclosureUrl,
None.gif    fp.EnclosureLength,
None.gif    fp.EnclosureType,
None.gif    fp.Creator,
None.gif    fp.CommentApiUrl,
None.gif    fp.CommentRssUrl,
None.gif    fp.CommentCount
None.gif
FROM     cs_Feed f,
None.gif    cs_FeedPost fp,
None.gif    cs_FolderFeed ff
None.gif
WHERE f.FeedId = fp.FeedId
None.gif  
AND f.FeedId = ff.FeedId
None.gif  
AND ff.UserId = @UserId
None.gif   
AND IsNull(ff.FolderId,-1= @FolderId
None.gif  
AND f.SettingsID = @SettingsID AND ff.SettingsID = @SettingsID
None.gif  
ORDER BY fp.FeedPostId DESC
None.gif
None.gif
None.gif
None.gif
None.gif  
END
None.gif
None.gif
ContractedBlock.gifExpandedBlockStart.gifcs_Folder_GetFolders
None.gifALTER  PROC [dbo].cs_Folder_GetFolders
None.gif    
@UserId INT,
None.gif    
@SettingsID INT,
None.gif    
@ParentFolderId INT = -1
None.gif
AS
None.gif
Begin
None.gif
ExpandedBlockStart.gifContractedBlock.gif   
/**//*创建临时表,然后删除,语句有点负责的样子,不过认真看就没问题了。*/       
None.gif    
Create Table #Temp ( FeedId int, FolderId int, CNT int )
None.gif    
None.gif    
Insert #Temp (FeedId, FolderId, CNT)
None.gif    
Select FeedId, cf.FolderId,
None.gif    (
None.gif        
select count(*from (Select top 50 f.FeedPostID, f.FeedId FROM cs_FeedPost f where f.FeedId = cf.FeedId order by PubDate DESC) fp left outer join cs_UserReadPost urp on fp.FeedPostID = urp.FeedPostID where fp.FeedId = cf.FeedId and urp.UserId IS NULL
None.gif    ) 
as [CNT] FROM cs_FolderFeed cf, cs_Folder ff where cf.FolderId = ff.FolderId and  IsNull(ff.ParentFolderId, -1= @ParentFolderId and cf.UserId = @UserId and cf.SettingsID = @SettingsID and ff.SettingsID = @SettingsID
None.gif
None.gif
None.gif    
SELECT     FolderId,
None.gif        UserId,
None.gif        FolderName,
None.gif        ParentFolderId
None.gif        ,
[UnreadCount] = (Select Sum(CNT) FROM #Temp where #Temp.FolderId = cs_Folder.FolderID)
None.gif    
FROM cs_Folder
None.gif    
WHERE UserId = @UserId
None.gif      
AND IsNull(ParentFolderId,-1=  @ParentFolderId
None.gif          
AND cs_Folder.SettingsID = @SettingsID
None.gif    
ORDER BY FolderName
None.gif
None.gif
None.gif
None.gif    
DROP Table #Temp
None.gif
None.gif  
END
None.gif

转载于:https://www.cnblogs.com/ruanbl/archive/2006/09/20/509380.html

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值