2014-07-02 65 views
0

如何更新添加列列的現值和新的更新值如何更新一列,每天明智

例..

如果countofcustomer列的值是5的昨天,今天如果V是獲得新的更新值

countofcustomer爲2,則列應得到更新爲7。

+0

'更新表設置countofcustomer = countofcustomer + 2' –

+0

@Nikil - 有可以是隨機值一次2個或5個以上,所以我想我不能在查詢 – user3737182

+0

加+2'更新表設置countofcustomer = countofcustomer +(從表中選擇count(*)其中added_date = sysdate)' –

回答

1
update table 
set value = v.value 
from table t join 
(Select Sum(value),customer 
from table 
where month(ENDDATETIME) = month(getdate())  
group by customer 
)v 
on v.customer = t.customer 
+0

@ Azar - 我明白月度明智,所以我應該得到本月的客戶數即7月1日至31日。上述查詢也給我上個月的計數。 – user3737182

+0

現在嘗試........ – Azar

+0

我使用在這種狀態下where子句「,其中ENDDATETIME> = DATEADD(DD,DATEDIFF(日,0,GETDATE()),0) 和ENDDATETIME <= DATEADD( DD,DATEDIFF(日,0,GetDate()),30)「但仍然沒有得到更新 – user3737182

0

我不知道如果我理解正確的questio N,但也許觸發可能是有用的:

msdn trigger:

時表引發事件(如更新),您可以執行的操作。

0

請嘗試:

update tbl set countofcustomer=countofcustomer + 2