根据父级名称找出所有子集的SQL语句
来源:互联网 发布:c语言字符数组默认 编辑:程序博客网 时间:2024/05/29 05:07
if exists (select 1
from sysobjects
where id = object_id('newtable1')
and type = 'U')
begin
drop table newtable1--用来存放所有子集ID的临时表
end
if exists (select 1
from sysobjects
where id = object_id('seaskytable')
and type = 'U')
begin
drop table seaskytable--中间过度的临时表
end
select B_P_ID into seaskytable from B_Province where B_P_Name like '%上海%'
select B_P_ID into newtable1 from seaskytable where B_P_ID is null
while exists(select * from B_Province where B_P_ParentID in (select * from seaskytable where B_P_ID not in (select * from newtable1)))
begin
SET IDENTITY_INSERT seaskytable off
SET IDENTITY_INSERT newtable1 on
insert into newtable1(B_P_ID) select B_P_ID from seaskytable where B_P_ID not in (select * from newtable1)
SET IDENTITY_INSERT newtable1 off
SET IDENTITY_INSERT seaskytable ON
insert into seaskytable(B_P_ID) select B_P_ID from B_Province where B_P_ParentID in (select * from seaskytable)
end
SET IDENTITY_INSERT seaskytable off
SET IDENTITY_INSERT newtable1 on
insert into newtable1(B_P_ID) select B_P_ID from seaskytable where B_P_ID not in (select * from newtable1)
select * from B_Province where B_P_ID in (select * from newtable1)
from sysobjects
where id = object_id('newtable1')
and type = 'U')
begin
drop table newtable1--用来存放所有子集ID的临时表
end
if exists (select 1
from sysobjects
where id = object_id('seaskytable')
and type = 'U')
begin
drop table seaskytable--中间过度的临时表
end
select B_P_ID into seaskytable from B_Province where B_P_Name like '%上海%'
select B_P_ID into newtable1 from seaskytable where B_P_ID is null
while exists(select * from B_Province where B_P_ParentID in (select * from seaskytable where B_P_ID not in (select * from newtable1)))
begin
SET IDENTITY_INSERT seaskytable off
SET IDENTITY_INSERT newtable1 on
insert into newtable1(B_P_ID) select B_P_ID from seaskytable where B_P_ID not in (select * from newtable1)
SET IDENTITY_INSERT newtable1 off
SET IDENTITY_INSERT seaskytable ON
insert into seaskytable(B_P_ID) select B_P_ID from B_Province where B_P_ParentID in (select * from seaskytable)
end
SET IDENTITY_INSERT seaskytable off
SET IDENTITY_INSERT newtable1 on
insert into newtable1(B_P_ID) select B_P_ID from seaskytable where B_P_ID not in (select * from newtable1)
select * from B_Province where B_P_ID in (select * from newtable1)
- 根据父级名称找出所有子集的SQL语句
- 多条件组合查询,并根据指定类别找出所有最小子类别的SQL语句备忘
- 找出当前页面执行的所有sql语句
- LeetCode(Subsets)找出一个集合的所有子集
- 利用格雷码找出集合的所有非空子集
- BackTrack-----找出一个集合的所有子集(78. Subsets)
- SQL中的CTE,查询所有的子集(子集的子集)比游标效率高
- 找出一个对象名称的所有出现处
- 获得数据库名称///////查询数据库里所有表的sql语句!
- 所有子集的和
- 根据当前日期获取当月内所有日期的SQL语句
- sql语句找出缺少的数
- 找出cpu占用率高的sql语句
- sql语句,如何找出重复的数据
- 找出存在性能问题的sql语句
- 找出执行效率低下的sql语句
- SQLServer找出执行慢的SQL语句
- SQLServer找出执行慢的SQL语句
- 颜色代码表 (颜色名称,颜色数值),可调试
- How To Pass Arrays Between Visual Basic and C
- 我是一块硬盘
- Third Normal Form (3NF)
- php文件上传方法分享~``
- 根据父级名称找出所有子集的SQL语句
- 星级评分的简化实现
- 迷茫
- 用.NET创建Windows服务
- 由浅到深了解JavaScript类
- 设计已死?
- C#中timer类
- Java中static、this、super、final用法
- 解决java+ajax的乱码问题