ALTER Proc [dbo].[p_GetServerDataCursor]
AS
BEGIN
IF EXISTS ( SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[#ttableName]') AND type IN ( N'U' ) )
BEGIN
DROP TABLE [dbo].[#ttableName]
END
IF EXISTS ( SELECT *
FROM sys.objects
WHERE object_id = OBJECT_ID(N'[dbo].[#tmpReturnData]')
AND type IN ( N'U' ) )
BEGIN
DROP TABLE [dbo].[#tmpReturnData]
END
declare @orderNum varchar(255)
--创建临时表存储tagId
create table #ttableName(id int identity(1,1),Orders varchar(255))
--创建临时表返回数据
create table #tmpReturnData(id int identity(1,1),openid varchar(100),tagid varchar(100))
--定义循环变量,行数,总数
declare @n int,@rows int,@count varchar(1000),@a varchar(100)
--查询去重复tagId插入ttableName中
insert #ttableName(orders) select distinct tagId from Log_TagIdRecord where openId !='null' and IsServer=0
--row获取tagid行数 rowcount 返回受上一语句影响的行数。如果行数大于20 亿,请使用ROWCOUNT_BIG。
select @rows =@@rowcount
set @n=1
while @n<=@rows
begin
--@count查询数量根据,ttableName表ID自增长根据@n循环每行数据
select @count=COUNT( distinct openId) from Log_TagIdRecord where tagId=(select Orders from #ttableName where id=@n) and openId !='null'and IsServer=0;
select @a=Orders from #ttableName where id=@n;
IF(@count>49)
BEGIN
insert #tmpReturnData select distinct top 50 openId,tagId from Log_TagIdRecord where tagId=(select Orders from #ttableName where id=@n) and openId !='null'and IsServer=0;
update Log_TagIdRecord set IsServer=1 where openId in (select openid from #tmpReturnData) and tagId in (select tagid from #tmpReturnData)
break;
END
--@n增加
select @n=@n+1
end
set @a='select * from #tmpReturnData'
EXEC (@a)
drop table #ttableName
drop table #tmpReturnData
END

最新文章

  1. Linux系统重要快捷键&amp; Shell 常用通配符
  2. poj 3744 Scout YYF I(概率dp,矩阵优化)
  3. ndk学习14: 进程
  4. Mysql 如何做双机热备和负载均衡
  5. java常见算法
  6. javascript事件委托和jQuery事件绑定on、off 和one
  7. mysql1130远程连接没有权限解决方法
  8. 关于php文件读取的一些学习记录
  9. Exception in thread "main" org.hibernate.MappingException: You may only specify a cache for root
  10. 》》HTML5 移动页面自适应手机屏幕四类方法
  11. vuejs、eggjs全栈式开发设备管理系统
  12. interrupt interrupted isInterrupted 方法对比、区别与联系 多线程中篇(八)
  13. linux常用命令 命令管道符
  14. 转-CSRF&amp;OWASP CSRFGuard
  15. oracle-企业信息化
  16. 5-安装sqoop
  17. 浅谈 iOS 中的 Activity Indicator
  18. Spring4笔记11--SSH整合2--SpringWeb
  19. 根据PV量来确定需要进行压测的并发量
  20. 40行代码爬取猫眼电影TOP100榜所有信息

热门文章

  1. vue操作的填坑之旅
  2. 叠加dgv中相同的行信息
  3. C# 最齐全的上传图片方法
  4. Django Model 基础
  5. Singleton Summary
  6. win7安装vs2017时闪退
  7. 【SP1811】 LCS - Longest Common Substring(SAM)
  8. 带你走进CSS定位详解
  9. python实现线性排序算法-计数排序
  10. Http请求-get和post的区别