SQL Server multi-table update/associated update

Source: Internet
Author: User

I tried multiple times and finally concluded that when multiple SQL Server tables are associated with update, an as Alias cannot be added to an external table, and a syntax error is returned.

Only the table name can be written as the prefix for reference and cannot be referenced using an alias.

The syntax can be referred to below


Update a set Field 1 = B table field expression, field 2 = B table field expression from B WHERE logical expression

For example:

The code is as follows: Copy code

UPDATE dbo. Table2

SET dbo. Table2.ColB = dbo. Table2.ColB + dbo. Table1.ColB

FROM dbo. Table2

Inner join dbo. Table1

ON (dbo. Table2.ColA = dbo. Table1.ColA );


Example 1:

Count the total revenue of a clerk in the current month's business system, and update it to the clerk table.

The code is as follows: Copy code

Update user set user. money = yeji_as.full_money from
(
Select sum (day_money) as full_money, user_id from yewu where yewu_date = '2013' group by user_id
) As yeji_as where yeji_as.user_id = user. user_id

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.