zoukankan      html  css  js  c++  java
  • SQL游标及sp_executesql用法

    DECLARE @MyCur CURSOR
     SET @MyCur = Cursor Local Scroll FOR SELECT TopicID,PostTable FROM TB_BBS_Topic WHERE BoardID = @SrcBoardID AND DATEDIFF(DAY,DateAndTime,GETDATE())> @Days
         OPEN @MyCur
         FETCH NEXT FROM @MyCur INTO @TopicID,@PostTable
         WHILE @@FETCH_STATUS = 0
         BEGIN
      SET @Sql = 'UPDATE '+ @PostTable + ' SET BoardID = '+ convert(varchar,@DestBoardID) + ' WHERE RootID = '+ convert(varchar,@TopicID)  
      EXEC @Sql
             FETCH NEXT FROM @MyCur INTO @TopicID,@PostTable
         END
     CLOSE  @MyCur
     Deallocate @MyCur  

    set @str_sql='SELECT @TotalRec=COUNT(AnnounceID) FROM '+ @PostTable +' WHERE ParentID <> 0 AND RootID ='+LTRIM(STR(@RootID))+' AND BoardID = '+LTRIM(STR(@BoardID))
    exec sp_executesql @str_sql,N'@TotalRec int output',@TotalRec output

  • 相关阅读:
    Redis其他命令
    Redis 键(key)
    Redis数据类型命令
    配置命令 CONFIG
    Redis简介
    idea破解
    jenkins+allure+testng
    Jenkins
    docker镜像
    docker命令
  • 原文地址:https://www.cnblogs.com/fery/p/1807653.html
Copyright © 2011-2022 走看看