sql语句问题,判断update如果为空则不更新数据
updatetest_v8_busy_revisittset(t.outbound_type,t.outbound_stat,t.outbound_count,t.use...
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, tbl_cust_data_table_0000000298 t2 where
t1.target_table='TBL_CUST_DATA_TABLE_0000000298' and t1.sales_results='CALL_NOT_CONN_SENDMSG'
and t2.field_50028161 = t.contact_id and t1.sales_time>=start_time and t1.sales_time<=end_time );
这条select语句为空就会更新全部数据,请问如何判断一下? 展开
(select '0','11','1',t1.sales_person,t1.sales_time from tbl_sp_sales_records t1, tbl_cust_data_table_0000000298 t2 where
t1.target_table='TBL_CUST_DATA_TABLE_0000000298' and t1.sales_results='CALL_NOT_CONN_SENDMSG'
and t2.field_50028161 = t.contact_id and t1.sales_time>=start_time and t1.sales_time<=end_time );
这条select语句为空就会更新全部数据,请问如何判断一下? 展开
3个回答
展开全部
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改了一下
更多追问追答
追问
select返回的是多行 不能更新多行
追答
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, tbl_cust_data_table_0000000298 t2 where
t1.target_table='TBL_CUST_DATA_TABLE_0000000298' and t1.sales_results='CALL_NOT_CONN_SENDMSG'
and t2.field_50028161 = t.contact_id and t1.sales_time>=start_time and t1.sales_time<=end_time )
where exists(select null from tbl_sp_sales_records t1, tbl_cust_data_table_0000000298 t2 where
t1.target_table='TBL_CUST_DATA_TABLE_0000000298' and t1.sales_results='CALL_NOT_CONN_SENDMSG'
and t2.field_50028161 = t.contact_id and t1.sales_time>=start_time and t1.sales_time<=end_time);
上面的SQL写的有问题,应该把and t2.field_50028161 = t.contact_id删除,所以还是在你的基础上改一下,更新部分没动,只加了where判断
展开全部
每种数据库的update都不太相同,你的数据库是啥?
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
展开全部
你update语句没有where条件啊,就算不为空更新的也是所有的吧?
加上where条件试试
加上where条件试试
更多追问追答
追问
有啊,在(select。。。里面),你的意思是外面?外面应该怎么加
追答
update xx set xx=xx where xx=xx
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询