易截截图软件、单文件、免安装、纯绿色、仅160KB

如果写递归sql语句 - MS-SQL Server / 应用实例

有两个同样的表结构 
表结构如下:
  id(序号) parentid (父结点序号) name(结点名称)
 表1 记录 1 0 aaa
  2 0 bbb
  3 1 ccc

  。。。。。。
表2 记录  
  1 0 bbb
  2 0 xxx

  。。。。
表1与表2都是树状结构记录。现需要将表1记录导入到表2中 ,表2中已经有部分记录,有些记录与表1中记录相同。
现需要将表1中的记录导入到表2中,需要判断表2中没有表1记录的需要全部导入,并且树状结构和表1中的结构一致。

用存储过程也可以。谢谢。


 
  
 
MRAK 回去再看

顶下



SQL code:


insert into 表2
select * from 表1 a where not exists
(select 1 from 表2 b where a.id=b.id and a.parentid=b.parentid and a.name=b.name)



引用
SQL codeinsertinto 表2select*from 表1 awherenotexists
(select1from 表2 bwhere a.id=b.idand a.parentid=b.parentidand a.name=b.name)

可以尝试

哦 效率啊效率

原来这样真的可以。。想了。没


相关问答:

access 中执行sql语句update不成功,求助!!!

access 中执行sql update语句时有时候成功有时候不成功,但是access中不出错误信息,不知道是什么原因,有哪位大侠知道,请帮忙啊
贴SQL语句,检查表、字段的有效性设置

sql 在查询分析器里面 执行很正常

是 ......

求一SQL - MS-SQL Server / 基础类

表如下
教室ID 座位数 开始时间 结束时间 2009年1月1日 2009年1月2日 2009年1月3日
  101 50 08:00 08:30 30 40 50  
  101 50 09:00 ......

求一SQL语句

原数据

商品    原价    打折方式1  折扣1    打折方式2  折扣2
笔记本  10000  NULL        0      NULL&nb ......

jsp链接sql2000的疑问?



type Exception report


message

description The server encountered an internal error () that prevented it from fulfilling this request.

exception

org.apache.jas ......

求一个SQL命令

有一张表(SHGL)
JLBH        LXR              LXDH            SHDZ
1            a ......
© 2009 ej38.com All Rights Reserved. 关于E健网联系我们 | 站点地图 | 赣ICP备09004571号