请教一条SQL修改添加语句 - MS-SQL Server / 应用实例
有两个表T1和T2,
T1如下:
编号 姓名 性别 部门
001 ZZ 男 业务部
002 YY 女 经销部
003 XX 女 生产部
004 WW 男 销售部
005 ……
T2如下:
编号 姓名 部门
001 ZZ 男 业务部
(无记录)
003 XX 女 销售部(不同)
005 ……
我想对比两个表中的编号,
找出T2中空缺的编号将T1的内容加上,已有的编号对应选项对比内容,如更改则T2也更改
就是跟着T1的标准走,请教大家怎么实现,谢谢!
是要触发器吗?
如果是一锤子买卖,则如下:
SQL code:
--1.update
update t2
set 姓名 = t1.姓名 ,
部门 = t1.部门
from t2 , t1
where t2.编号 = t1.编号
--2.insert
insert into t2 select 编号, 姓名 ,部门 from t2 where t2.编号 not in (select 编号 from t1)
SQL code:
if not exists(select 1 from t1 inner join t2 where t1.编号 = t2.编号)
insert into t2(编号,姓名,性别,部门) select 编号,姓名,性别,部门 from t1
else
update t1 set 部门 = t2.部门 from t2 where t1.编号 = t2.编号
-- 只是一次性的,如果一直要这样,要做触发器
我是用VC++6.0编的,就想每次按键执行一次这功能
SQL code
Code highlighting produced by Actipro CodeHighlighter (freeware)
http://www.C
相关问答:
type Exception report
message
description The server encountered an internal error () that prevented it from fulfilling this request.
exception
org.apache.jas ......
我一个项目,有个插入操作,具体是这样的:
我有进货信息表。在出货时选择相应的进货信息,输入数量,选择部门后,点保存按钮,由于网络延时,点一下没有反映,于是用户就又点一下,导致一次插入了两条记录:
例:
......
现在有两张表:文章主表A(articleId,articleTitle),文章评论表B(commentId,articleId,commentTitle)
现在我想实现这样的功能:列出文章列表,其中每篇文章标题下面列出此文章的前2个文章评论,请问sql语句怎么写啊 ......
tab1 字段:billdate,goodsid,incount,inmoney,outcount,outmoney,endprice,endcount,endamt
tab2 字段:goodsid,goodskind(商品类型)
tab3 字段:goodskind(商品类型),kindname
结果:
得到商品类型在一段时间 ......
通过NAME字段条件查询一个数据表,假设我有100个姓名,有以下两个方法,
方法1:
把100个Name 组成一个SQL语句,比如 Select * from tmp_table where Name='张三' or Name ='李四' Or ...Or Name='第一百个姓名'
......