首页 诗词 字典 板报 句子 名言 友答 励志 学校 网站地图
当前位置: 首页 > 教程频道 > 开发语言 > VB >

Update语句更新多种结果的有关问题

2012-02-03 
Update语句更新多种结果的问题?根据表中的一个日期数据进行更新:IDOutDate12010-1-822010-1-1532010-3-142

Update语句更新多种结果的问题?
根据表中的一个日期数据进行更新:

ID OutDate 
1 2010-1-8 
2 2010-1-15 
3 2010-3-1 
4 2010-4-1 
5 2010-5-1 


如果日期为2010-1-8,就将其更新为2010-1-1 
如果日期为2010-1-15,就将其更新为2010-1-4

我现在写了2个Update语句来完成: 
1.Update table1 set OutDate=#2010-1-8# where OutDate=#2010-1-1# 
2.Update table1 set OutDate=#2010-1-15# where OutDate=#2010-1-4# 

请教有没有其它方法用一个Update语句就可以完成上面的2次更新?

Access里面没有SQL的case when,只有iif,但是iif只能写怎么来写呢?iif里面只能写一个条件的啊?

[解决办法]
你哪什么数据库?
case when可用得话
试试
iif((OutDate = '2010-1-8' or OutDate = '2010-1-15' ),iif(
OutDate = '2010-1-8' ,'2010-1-1','2010-1-4)),OutDate)
瞎搞的。
[解决办法]
如果日期为2010-1-8,就将其更新为2010-1-1 
如果日期为2010-1-15,就将其更新为2010-1-4 

我现在写了2个Update语句来完成: 
1.Update table1 set OutDate=#2010-1-8# where OutDate=#2010-1-1# 
2.Update table1 set OutDate=#2010-1-15# where OutDate=#2010-1-4# 

请教有没有其它方法用一个Update语句就可以完成上面的2次更新? 
---------------------------------
你1、2二个语句的意思明明是:
将OutDate为2010-1-1的数据更新为OutDate=2010-1-8 
将OutDate为2010-1-4的数据更新为OutDate=2010-1-15
和你的描述相反,所以不知道到底是什么要求,如果只改以上二个日期的数据:
Update table1 
set OutDate=iif(OutDate=#2010-1-1#,#2010-1-8#,#2010-1-15#)
where OutDate in (#2010-1-1#,#2010-1-4#) 




 

热点排行