SQL Bulk operations (presence of updates, non-existent inserts)

Source: Internet
Author: User

Tags: sql2012-09-06 18:13 2408 People read comments (0) favorite reports Classification:SQL Server (123)

Copyright NOTICE: This article for Bo Master original article, without Bo Master permission not reproduced.

[SQL]View PlainCopy
  1. Update a SET a.name=
  2. (
  3. Select B.NAME from #tmpTB2 b where b.id=a.id
  4. )
  5. From #tmpTB3 A
  6. Insert INTO #tmpTB3
  7. SELECT * from #tmpTB2 B
  8. where b.ID not in (select ID from #tmpTB3)
The above are: existing updates, non-existent inserts


The following is a batch update of an identity field:

[SQL]View PlainCopy
  1. UPDATE A SET a.provider_isactive=
  2. (
  3. SELECT case
  4. (
  5. SELECT 1 from
  6. (
  7. SELECT DISTINCT provider_system_provider_id
  8. From Your_db_name. [dbo]. [Your_table_name2] P
  9. WHERE p.data_source = ' Ika ' and soft_delete_flag = ' n ' and provider_active_flag = ' y ' /c6>
  10. ) B WHERE b.provider_system_provider_id = left (a.external_provider_id,7)
  11. ) is NULL and then 0 ELSE 1 END as provider_isactive
  12. )
  13. From Your_db_name. [dbo]. [Your_table_name1] A
  14. --SELECT COUNT (*) from Your_db_name. [dbo]. [Your_table_name1] A WHERE provider_isactive=0

SQL Bulk operations (presence of updates, non-existent inserts)

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.