sql語句問題,判斷update如果為空則不更新資料

2021-05-16 16:33:55 字數 2089 閱讀 4745

1樓:匿名使用者

update     test_v8_busy_revisit t

set    (t.outbound_type,t.outbound_stat,t.

outbound_count,t.user_code,t.outbound_time)=

(select  '0','11','1',t1.sales_person,t1.sales_time

from  tbl_sp_sales_records t1

where  t1.target_table='tbl_cust_data_table_0000000298'

and  t1.sales_results = 'call_not_conn_sendmsg'

and  t1.sales_time   >= start_time

and  t1.sales_time   <= end_time

and  t2.field_50028161 = t.contact_id

)where t.contact_id in(select t2.field_50028161 from tbl_cust_data_table_0000000298 t2)

;你的sql中,select語句查詢了t1,t2表,貌似兩表連線,可是條件都是在t1表上,t2和t1沒有關聯,t2卻和更新的表t有(t2.field_50028161 = t.contact_id

)這個關聯,奇怪

所以只把你的sql改了一下

2樓:匿名使用者

你update語句沒有where條件啊,就算不為空更新的也是所有的吧?

加上where條件試試

3樓:匿名使用者

每種資料庫的update都不太相同,你的資料庫是啥?

sql更新語句 若某欄位為空則更新此欄位否則不更新

4樓:德陽小孩

-- mysql的寫法,其他資料庫同理,只有當前時間的引數不同

update test set endtime=now() where endtime is null;

5樓:

update test

set stoptime=getdate()where

(select count(*) from testwhere (id=(select max(id) from test)) and (stoptime is null or stoptime='')

)>0

oracle sql語句 若某欄位為空則更新此欄位否則更新另一個欄位,只用一個sql語句

6樓:千鋒教育

oracle中條件更新用case when結構,舉例如下:用法如下:

update test set column1=(case testcond

when ' ' then '***'

else yyy end )

這樣就可以更具某個字

版段的值來更權新另外一個欄位了。

7樓:匿名使用者

update ss set bengtime=decode(bengtime ,null,sysdate-1,bengtime),endtime=decode(bengtime,null,endtime,sysdate) where id=***xx;

8樓:匿名使用者

通用sql:

update ss

set bengtime = case when bengtime is null then sysdate else bengtime end,

endtime = case when endtime is null then sysdate else endtime end

where id = ...

或者,簡單回點:答

update ss

set bengtime = nvl(bengtime,sysdate),

endtime =nvl(endtime,sysdate)where id = ...

SQL語句表中自動批量update

update 表 bai1 set 欄位 du1 select 表2.欄位1 from 表2 where 表2.航班 zhi號dao 表1.航班號 and 表2.日期 表1.日期 where exists 專select 1 from 表2 where 表2.航班號 表1.航班號 and 表2.日期...

sql 問題,sql語句的問題?

請檢查 1,表名,就是 insert into 表名 values 有沒有錯誤 2,insert into的values 必須包含整個表的所有列,你的表只有3個列嗎?其他的可以根據列的資料型別用逗號或者兩個單引號加逗號實現。比如 insert into 表名 values 40001,3,id列,就...

php關於update語句的問題

result mysql query sql,conn 這一行上面用。var dump sql 把 sql列印出來看看是什麼,直接執行列印出來的sql看報不報什麼錯誤。php中執行update語句的問題 php update語句的問題 要 的,你就別截圖唄,我們改著也方便。你把 id isset p...