SQL更新表数据查询

时间:2012-10-31 18:53:59

标签: sql sql-server

我想运行更新查询以在我的案例2012-10-28 03:31:01 to 2012-10-28 08:31:01中的指定日期之间更新PercentAvailability列值0到100。见下图。

enter image description here

如何运行查询以在指定日期之间更新上述数据?

注意:我有很多具有此问题的ApplicationID,所以我怎么能对所有ApplicationID运行查询,我相信我们需要运行JOIN语法,但如果你给出一些提示,那将会很好。

1 个答案:

答案 0 :(得分:5)

使用此查询

update your_table
set PercentAvailability = 100
where PercentAvailability = 0
and [DateTime] between '2012-10-28 03:31:01' and '2012-10-28 08:31:01'

或者如果您只想为特定的ApplicationID更新相同的内容,请执行

update your_table
set PercentAvailability = 100
where PercentAvailability = 0
and [DateTime] between '2012-10-28 03:31:01' and '2012-10-28 08:31:01'
and ApplicationID = 1235

或多个ApplicationID执行

update your_table
set PercentAvailability = 100
where PercentAvailability = 0
and [DateTime] between '2012-10-28 03:31:01' and '2012-10-28 08:31:01'
and ApplicationID in (1235, 1236, 1237)

或者对于一个大数字或ApplicationID你可以做一个子查询

update your_table
set PercentAvailability = 100
where PercentAvailability = 0
and [DateTime] between '2012-10-28 03:31:01' and '2012-10-28 08:31:01'
and ApplicationID in (select ApplicationID from another_table where somecondition)