zoukankan
html css js c++ java
获取某命名规则下一系列表的总条数
SQLServer(T-SQL):
--
获取某命名规则下的
--
场景:有1000个后缀逐渐递增的表(如果是上万了也可做相应的改动实现),获取这些表总的数据条数
--
表的形式:tb_user000,tb_user001,tb_user010,tb_user011,tb_user999
--命名规则
:000,001...009,010,011..999
declare
@i
int
--
表开始后缀
declare
@str
nvarchar
(
1000
)
--
执行语句
declare
@tab
varchar
(
100
)
--
表前缀
declare
@tab_suffix
varchar
(
10
)
--
表后缀
declare
@max
int
--
表个数
set
@i
=
0
set
@tab
=
'
tb_user
'
set
@max
=
1000
if
exists
(
select
*
from
tempdb.dbo.sysobjects
where
id
=
OBJECT_ID
(
'
tempdb..#t1
'
)
and
xtype
=
'
U
'
)
drop
table
#t1
create
table
#t1(id
int
identity
(
1
,
1
),num
int
,tab
varchar
(
100
))
while
@i
<
@max
begin
if
@i
>=
0
and
@i
<
10
set
@tab_suffix
=
'
00
'
else
if
@i
>
9
and
@i
<
100
set
@tab_suffix
=
'
0
'
else
if
@i
>
99
and
@i
<
1000
set
@tab_suffix
=
''
set
@str
=
N
'
insert into #t1(num,tab) select Total,
'''
+
@tab
+
@tab_suffix
+
cast
(
@i
as
varchar
)
+
'''
from
(select Total = count(*) from
'
+
@tab
+
@tab_suffix
+
cast
(
@i
as
varchar
)
+
'
) a
'
print
@str
;
exec
sp_executesql
@str
;
set
@i
=
@i
+
1
;
end
select
num,tab,sum_num
from
(
select
sum
(num)
as
sum_num
from
#t1) b,#t1
显示结果如下:
作者:
青羽
查看全文
相关阅读:
【转】git教程
Ubuntu下编译运行Kamailio
windows下编译FreeSwitch
自己常用的wireshark过滤条件
CSRF 漏洞原理详解及防御方法
Sql 注入详解:宽字节注入+二次注入
Kali下Ettercap 使用教程+DNS欺骗攻击
Sql注入的分类:数字型+字符型
Windows Server 2012 R2 配置FTP服务器
Kali Linux 初始化配置:Apache2 /SSH /FTP
原文地址:https://www.cnblogs.com/tenghoo/p/1238808.html
最新文章
说说Runnable与Callable
小笔记01
看图说说JVM老年代垃圾收集器
VM参数收集(部分)
Windows搭建Log4Net+FileBeat+ELK日志分析系统过程
知识点总结:Linq和Lambda
查询一天的小时数
Winform程序在XP系统上双击运行无反应解决方法
IIS部署时failed to execute url 解决方法
IIS部署时未能加载程序集"System.Web.Http.WebHost"解决方法
热门文章
Sql保留两位小数方法
进入网页开始计时,关闭页面时触发操作事件
赋予Winform程序管理员访问权限
Sql Server统计报表案例
搭建turnserver
【转】使用PowerISO软件制作Centos7启动U盘
【转】STUN简介 NAT的UDP简单穿越
【转】sip中的subscribe和notify扩展应用技术
sip比较好的博客
【转】SIP初步
Copyright © 2011-2022 走看看