如何在SQL Server中使用不同表在一个查询中进行选择和更新? [英] How to SELECT and UPDATE in one query using Different Tables in sql server?

查看:99
本文介绍了如何在SQL Server中使用不同表在一个查询中进行选择和更新?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

如何在SQL Server中使用不同表在一个查询中进行选择和更新?

How to SELECT and UPDATE in one query using Different Tables in sql server?

推荐答案



这可能对您有用.

从table1,table2中选择table1.column1,table2.column2 WHERE table1.column1 = table2.column1;

您可以使用存储过程来更新不同的表列.

谢谢
Saranya1388
Hi,

This may useful for you.

SELECT table1.column1, table2.column2 FROM table1, table2 WHERE table1.column1 = table2.column1;

You can use the stored procedure for update the different table columns.

Thanks
Saranya1388


已解决.:rose:

It is Solved.:rose:

IF  EXISTS  (SELECT 1   FROM    InsCarrier  WHERE   (InsCarrierId = @InsCarrierId))
        UPDATE  InsCarrier
        SET     UserId = @UserId,InsCarrierName=@InsCarrierName
        WHERE   (InsCarrierId = @InsCarrierId)
    ELSE
        INSERT  INTO    InsCarrier  (UserId,InsCarrierName)
                        VALUES      (@B2bUserId,@InsCarrierName)


在我更新记录时,则所选记录的ID是相同的.
during i will update the record, then the Selected record id is same.


这篇关于如何在SQL Server中使用不同表在一个查询中进行选择和更新?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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