首页 诗词 字典 板报 句子 名言 友答 励志 学校 网站地图
当前位置: 首页 > 教程频道 > 数据库 > IBM DB2 >

存储过程小疑点,更新符合条件的表字段内容

2012-02-17 
存储过程小问题,更新符合条件的表字段内容。表table1(id1,date),table2(id1,id2,fd2)当给的条件日期tmpdate

存储过程小问题,更新符合条件的表字段内容。
表table1(id1,date),table2(id1,id2,fd2)
当给的条件日期tmpdate在table1能找到时(即select count() from table1 where date=tmpdate不为空记录),则更新table2的fd2字段值为‘aaa’(条件where table1.id1=table2.id1),如果没有找到时,更新为‘bbb’(条件where table1.id1=table2.id1)
怎样写语句,求解!!!

[解决办法]

SQL code
update table2 set fd2 = (  select case when table1.id1 is null then 'bbb' else 'aaa' end  from table1  where table1.id1 = table2.id1    and table1.date = tmpdate);
[解决办法]

教你个技巧:下次,你不用发那么多个贴,你可以发一个100分的,回答你的人肯定很多
[解决办法]

[解决办法]
不是,就是我写的那样
[解决办法]
上面的都不对:
SQL code
update table2 set fd2 = 'aaa'where exists(  select id1 from table1  where table1.id1 = table2.id1    and table1.date = tmpdate);update table2 set fd2 = 'bbb'where exists(  select id1 from table1  where table1.id1 = table2.id1    and table1.date <> tmpdate); 

热点排行