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
- Update a SET a.name=
- (
- Select B.NAME from #tmpTB2 b where b.id=a.id
- )
- From #tmpTB3 A
- Insert INTO #tmpTB3
- SELECT * from #tmpTB2 B
- 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
- UPDATE A SET a.provider_isactive=
- (
- SELECT case
- (
- SELECT 1 from
- (
- SELECT DISTINCT provider_system_provider_id
- From Your_db_name. [dbo]. [Your_table_name2] P
- WHERE p.data_source = ' Ika ' and soft_delete_flag = ' n ' and provider_active_flag = ' y ' /c6>
- ) B WHERE b.provider_system_provider_id = left (a.external_provider_id,7)
- ) is NULL and then 0 ELSE 1 END as provider_isactive
- )
- From Your_db_name. [dbo]. [Your_table_name1] A
- --SELECT COUNT (*) from Your_db_name. [dbo]. [Your_table_name1] A WHERE provider_isactive=0
SQL Bulk operations (presence of updates, non-existent inserts)