如何更新来自其他表的值的表? [英] How to update table where value coming from other table?

查看:72
本文介绍了如何更新来自其他表的值的表?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

如果其他表中的SMS可用,我想更新表格我的代码

  update  tblSMSSendData  set  tblSMSSendData.SMSCAMPID =( select  dbo.tblCampaignMaster.ID 来自 dbo.tblCampaignMaster 其中 tblSMSSendData.SMSTEXT = '  HERO City Motors Mega Scooter提供至7月20日,低首付款Rs.3500。投资回报率12%,免费头盔,保险,交换奖金和礼品礼品 -  9865209696 *'



和错误是

消息512,级别16,状态1,行6 
子查询返回的值超过1。当子查询遵循=,!=,<,< =,>,> =或子查询用作表达式时,不允许这样做。
该声明已被终止。





我尝试过:



  update  tblSMSSendData  set 来自 dbo.tblCampaignMaster 其中 tblSMSSendData.SMSTEXT = '  HERO City Motors Mega Scooter报价截至7月20日,低价付款Rs.3500。投资回报率12%,免费头盔,保险,交换奖金和礼品礼品 -  9865209696 *'

解决方案

< blockquote>首先将tblCampaignMaster.ID读入变量,然后使用该变量更新tblSMSSendData.SMSCAMPID。​​

 声明  @ id   int  

选择 @ id = ID 来自 dbo.tblCampaignMaster cm
其中 cm.SMSTEXT = ' HERO City Motors Mega Scooter报价截至7月20日,低预付款Rs 0.3500。投资回报率12%,免费头盔,保险,交换奖金和Referal Gift - 9865209696 *'

update tblSMSSendData set SMSCAMPID = @ id


你好,



避免在这里使用子查询作为多个值返回从你的条件。



尝试更新From语句,如下所示:



 更新 tblSMSSendData 
SET tblSMSSendData.SMSCAMPID = tblCampaignMaster.tblCampaignMaster.ID
FROM dbo.tblCampaignMaster
WHERE tblSMSSendData.SMSTEXT =
' HERO City Motors Mega Scooter提供至7月20日,低首付款Rs.3500。 ROI 12%,免费头盔,
保险,交换奖金& Referal Gift - 9865209696 *'





如果解决方案不能满足您的要求,请告诉我。


I want to update table if SMS is available in other table here my code

update tblSMSSendData set tblSMSSendData.SMSCAMPID=(select dbo.tblCampaignMaster.ID from dbo.tblCampaignMaster where tblSMSSendData.SMSTEXT='HERO City Motors Mega Scooter offer till 20th July, Low Down Payment Rs.3500. ROI 12%, FREE Helmet, Insurance, Exchange Bonus & Referal Gift - 9865209696*')


and error is

Msg 512, Level 16, State 1, Line 6
Subquery returned more than 1 value. This is not permitted when the subquery follows =, !=, <, <= , >, >= or when the subquery is used as an expression.
The statement has been terminated.



What I have tried:

update tblSMSSendData set tblSMSSendData.SMSCAMPID=(select dbo.tblCampaignMaster.ID from dbo.tblCampaignMaster where tblSMSSendData.SMSTEXT='HERO City Motors Mega Scooter offer till 20th July, Low Down Payment Rs.3500. ROI 12%, FREE Helmet, Insurance, Exchange Bonus & Referal Gift - 9865209696*')

解决方案

First read tblCampaignMaster.ID into a variable and then use that variable to update tblSMSSendData.SMSCAMPID.

declare @id int

select @id=ID from dbo.tblCampaignMaster cm
where cm.SMSTEXT='HERO City Motors Mega Scooter offer till 20th July, Low Down Payment Rs.3500. ROI 12%, FREE Helmet, Insurance, Exchange Bonus & Referal Gift - 9865209696*'

update tblSMSSendData set SMSCAMPID=@id


Hello,

Avoid use of Sub-query here as multiple values return from your condition.

Try Update From statement as shown below:

UPDATE tblSMSSendData 
SET tblSMSSendData.SMSCAMPID= tblCampaignMaster.tblCampaignMaster.ID 
FROM dbo.tblCampaignMaster 
WHERE tblSMSSendData.SMSTEXT=
'HERO City Motors Mega Scooter offer till 20th July, Low Down Payment Rs.3500. ROI 12%, FREE Helmet, 
Insurance, Exchange Bonus & Referal Gift - 9865209696*'



Please let me know if the solution doesn't suffice your requirement.


这篇关于如何更新来自其他表的值的表?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆