SQL Updates an example of another table based on one table and the problems that may be encountered

Source: Internet
Author: User
Tags one table truncated

Example:

Update a set a.name=b.name1 from a, where a.id=b.id

Example extension: How do I change strings to scientific notation when we update them?

A: Convert with cast, or double cast

Update Loaneeexpand set Loaneeexpand.phone=cast (CAST (TT. PHONE as Decimal (18,0) as nvarchar ()) from Loaneeexpand, TT where Loaneeexpand. id=tt.id

Again, the example extends the problem: update

String or binary data would be truncated.
The statement has been terminated.

string or binary data will be truncated.
The statement has been terminated. What to do?

It is clear that the field of the table you are updating is not long enough, but query all the true lengths of Table B Len (b.name) <20. Matches the length of the field in Table A, why is this?

A: When updating Table A, and is not calculated according to the actual length of table B, but according to the definition of Table B field length, all the table a needs to modify the length of the field, according to table B field length set.

SQL Updates an example of another table based on one table and the problems that may be encountered

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.