更新多个表中的一条记录 [英] Update a record in multiple table

查看:70
本文介绍了更新多个表中的一条记录的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

大家好
我有一个程序,我从前端传递参数以更新三个表,但不是不更新.

Hi All
I have a procedure where I m passing parameter from front end to update three table but it is not it is not updating.

BEGIN
               UPDATE CNMPNT  SET
               CUSTOMER_ALPHA=@ChangeAlphaPoiner
              WHERE
               CUSTOMER_ALPHA=@aplhaPointer AND
               ltrim(Rtrim(replace(CUSTOMER_ID,char(0),''))) IN (@CustomerIDs)
          (rtrim(replace('0045864',char(0),'')),replace('0046677',char(0),''))'0045864','0046677') (LTRIM(RTRIM(replace('0045864',char(0),''))),LTRIM(RTRIM(replace('0046677',char(0),''))))           (rtrim(replace('0045864',char(0),'')),replace('0046677',char(0),''))          (ltrim(rtrim(replace('0045864',char(0),''))))--,replace('0046677',char(0),'')))
            '%0045864' ='0046677'
               UPDATE CMAPNT  SET
               CUSTOMER_KEY=@ChangeAlphaPoiner
                              WHERE
               CUSTOMER_KEY=@aplhaPointer AND
               ltrim(Rtrim(replace(CUSTOMER_ID,char(0),''))) IN (@CustomerIDs)
            ('0045864','0046677') like '0062076'=@aplhaPointer
               UPDATE CUSMAS  SET
               ALPHA_POINTER=@ChangeAlphaPoiner
               WHERE
               ALPHA_POINTER=@aplhaPointer AND
               ltrim(Rtrim(replace(cust_id,char(0),''))) IN (@CustomerIDs)
               '%0045864%','0046677') ='0062076'
            END




请帮助




Please help

推荐答案

您提供的代码段至少对我来说似乎不可读.但是我可以建议另一种更好的方法来完成您要完成的任务.您可以在上下文中使用触发器.如果当前表中的记录已成功更新,则可以使用触发器将记录更新到下一个表.

例如:

The snippet you provided seems unreadable to me at-least. But I can suggest another better way of doing the task you are trying to achieve. You can use triggers in your context. Using triggers, you can update the record to next tables if the record has been successfully updated in the current table.

For eg:

create trigger u_authors on authors for update
as
Insert into log_authors (au_id) select au_id from inserted
go



希望这可以帮助. :rose:

Anurag



Hope this helps. :rose:

Anurag


我评论了没有任何意义的代码(如果运行,实际上会失败).
I commented the code that does not make any sense (actually will fail if run).
BEGIN
               UPDATE CNMPNT  SET
               CUSTOMER_ALPHA=@ChangeAlphaPoiner
              WHERE
               CUSTOMER_ALPHA=@aplhaPointer AND
               ltrim(Rtrim(replace(CUSTOMER_ID,char(0),''))) IN (@CustomerIDs)
/*        (rtrim(replace('0045864',char(0),'')),replace('0046677',char(0),''))'0045864','0046677') (LTRIM(RTRIM(replace('0045864',char(0),''))),LTRIM(RTRIM(replace('0046677',char(0),''))))           (rtrim(replace('0045864',char(0),'')),replace('0046677',char(0),''))          (ltrim(rtrim(replace('0045864',char(0),''))))--,replace('0046677',char(0),'')))
            '%0045864' ='0046677'
*/
               UPDATE CMAPNT  SET
               CUSTOMER_KEY=@ChangeAlphaPoiner
                              WHERE
               CUSTOMER_KEY=@aplhaPointer AND
               ltrim(Rtrim(replace(CUSTOMER_ID,char(0),''))) IN (@CustomerIDs)
/*
            ('0045864','0046677') like '0062076'=@aplhaPointer
*/
               UPDATE CUSMAS  SET
               ALPHA_POINTER=@ChangeAlphaPoiner
               WHERE
               ALPHA_POINTER=@aplhaPointer AND
               ltrim(Rtrim(replace(cust_id,char(0),''))) IN (@CustomerIDs)
/*
               '%0045864%','0046677') ='0062076'
*/
            END


这对您有用吗?


Would this work for you?


这篇关于更新多个表中的一条记录的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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