• 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

  • 相关阅读:
    下载文件
    利用 js 获取地址栏参数
    子组件向父组件传值
    cordova 插件 调用iOS社交化分享(ShareSDK:微信QQ分享)
    cordova 企业应用打包Archive的时候报 "#import <Cordova file not found"
    企业应用打包的时候 修改ipa包的bundle identifier
    Mac下利用safari调试 Cordova的WebApp
    Mac下利用Cordova打包 iOS App以及出现的问题
    数据库设计流程
    Javascript 获取dom的宽度 随笔一
  • 原文地址:https://www.cnblogs.com/summerGraden/p/11522594.html
Copyright © 2020-2023  润新知