读书人

Where 条件,该如何处理

发布时间: 2012-12-30 10:43:15 作者: rapoo

Where 条件

update dbo.RPT_resultA41 set BudgetAvgPerMth=BudgetYtd/9        
from dbo.RPT_resultA41
where CompanyID=1 and classify=-1

这个 where CompanyID=1 and classify=-1条件属于UPdate 条件是还是 from dbo.RPT_resultA41的条件呢!
update dbo.RPT_resultA41 set BudgetAvgPerMth=(Select BudgetYtd/9 from dbo.RPT_resultA41
where CompanyID=1 and classify=-1)
where CompanyID=1 and classify=-1

这样写是同样结果的,那条件是怎样判断的呢?
[解决办法]
update dbo.RPT_resultA41 set BudgetAvgPerMth=BudgetYtd/9
from dbo.RPT_resultA41
where CompanyID=1 and classify=-1
红色部分完全是多余的
[解决办法]
属于from 的条件。其实update的比较完整的格式是:
update tb
set xx=xx
from tb
where
无论单表还是多表都是,只是有些可以省略而已

读书人网 >SQL Server

热点推荐