zoukankan      html  css  js  c++  java
  • sqlsrv使用两个游标

    /*单独查询用户表, 分页,显示资源数和点赞数 */

    DECLARE @count INT,
    @pageindex INT,
    @count1 INT
    SET @count = 6
    SET @pageindex = 0
    SET @count1 = 3
    SELECT
    top ( @count ) UserAccount.NickName,
    UserAccount.HeadPhoto,
    ( SELECT count( id ) FROM UserAccount ) AS count
    FROM
    UserAccount
    WHERE
    ID NOT IN ( SELECT top ( @pageindex * @count ) ID FROM UserAccount ) BEGIN
    DECLARE
    @a INT,
    @error INT DECLARE
    @temp VARCHAR ( 50 )
    SET @a = 1
    SET @error = 0 DECLARE
    order_cursor CURSOR FOR (
    SELECT
    top ( @count ) UserAccount.NickName
    FROM
    UserAccount
    WHERE
    ID NOT IN ( SELECT top ( @pageindex * @count ) ID FROM UserAccount )
    ) OPEN order_cursor FETCH next
    FROM
    order_cursor INTO @temp
    WHILE
    @@FETCH_STATUS = 0 BEGIN
    SELECT
    top ( @count1 ) UserAccount.NickName,
    UserAccount.HeadPhoto,
    StandardResources.ID,
    StandardResources.UpdateTime,
    StandardResources.CoverImg,
    ( SELECT count( StandardResources.ID ) FROM StandardResources WHERE StandardResources.UploaderID = @temp ) AS IDAll,
    ( SELECT sum( StandardResources.GiveLike ) FROM StandardResources WHERE StandardResources.UploaderID = @temp ) AS GiveLikeAll
    FROM
    UserAccount,
    StandardResources
    WHERE
    UserAccount.NickName = @temp
    AND UserAccount.NickName = StandardResources.UploaderID
    GROUP BY
    UserAccount.NickName,
    UserAccount.HeadPhoto,
    StandardResources.ID,
    StandardResources.CoverImg,
    StandardResources.UpdateTime
    ORDER BY
    StandardResources.UpdateTime DESC;

    SET @a = @a + 1
    SET @error = @error + @@ERROR FETCH next
    FROM
    order_cursor INTO @temp
    END CLOSE order_cursor DEALLOCATE order_cursor
    END
    go

    /*单独资源表和关注表,显示资源总数,点赞和是否关注*/

    declare @count int,@pageindex int
    set @count=3
    set @pageindex=1
    begin
    declare @a int,@error int
    declare @temp varchar(50)
    set @a=1
    set @error=0
    declare order_cursor cursor
    for (
    SELECT top(@count)
    UserAccount.NickName
    FROM
    UserAccount
    WHERE
    ID NOT IN ( SELECT top(@pageindex*@count) ID FROM UserAccount )
    )
    open order_cursor
    fetch next from order_cursor into @temp
    while @@FETCH_STATUS = 0
    begin
    SELECT
    (@temp) as curdesigner,
    ( SELECT count( ID ) FROM StandardResources WHERE UploaderID = @temp ) AS ProductsAll,
    ( SELECT sum( GiveLike ) FROM StandardResources WHERE UploaderID = @temp ) AS GiveLikeAll,
    ( SELECT count(ID) FROM [AttentionPool] WHERE NickName ='偏执的小冰' and AttentionNickName=@temp) AS Beattentionedbool
    set @a=@a+1
    set @error= @error + @@ERROR
    fetch next from order_cursor into @temp
    end
    close order_cursor
    deallocate order_cursor
    end
    go

  • 相关阅读:
    pwdLastSet AD
    快递条形码类型
    Sharepoint 应用程序池自动停止
    Visual Studio 2015安装后“无法启动iis express web 服务器”
    Knockout自定义绑定数据逻辑
    Knockout基本绑定数据
    TableAttribute同时存在于
    微服务架构下的鉴权,怎么做更优雅?
    使用 Yopto 插件给商品添加评论
    Docker 基本概念
  • 原文地址:https://www.cnblogs.com/summerGraden/p/11522594.html
Copyright © 2011-2022 走看看