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

请教一条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


相关问答:

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 - MS-SQL Server / 疑难问题

sql的软件在哪里可以下啊!在网上找了蛮多都用不了啊

随便搞一D版吧,

迅雷第一个就可以用
2000,2005都这样

http://119.147.41.16/down?cid=0698C2D64D7D637D90A6D2482298E6717D4F15CD&t=2&fmt=-1 ......

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

tab1 字段:billdate,goodsid,incount,inmoney,outcount,outmoney,endprice,endcount,endamt
tab2 字段:goodsid,goodskind(商品类型)
tab3 字段:goodskind(商品类型),kindname
结果:
得到商品类型在一段时间 ......

sql语句问题 - MS-SQL Server / 疑难问题

现在有一个部门表dept(部门名称,部门号。。)有一个人员表emp(姓名,人员编号,职位,薪资,部门)
emp表中的内容是这样的:
a 1 工程师 3000 软件部
b 2 普通员工 2000 硬件部
c 3 工程师 4000 硬件部
d ......

sql语句问题 - Java / Web 开发

select o_customer,o_price from orders having o_price >=avg(o_price)
select o_customer,o_price from orders where o_price >=(select avg(o_price) from orders)
我感觉没有区别啊,怎么在mysql会有 ......
© 2009 ej38.com All Rights Reserved. 关于E健网联系我们 | 站点地图 | 赣ICP备09004571号