將查到的資料插入乙個自增編號的臨時表

2021-05-24 12:23:02 字數 871 閱讀 8209

if exists(select name from sysobjects where name='autotemp' and type='u') begin drop table dbo.autotemp end//如果系統中有這張白表就先刪除

select id=identity(bigint,1,1),bb.* into dbo.autotemp from (//id為自增編號

select distinct top 2000

a.pk_id as account_id,

233 as project_id, //將233作為一列專案編號

a.busi_telareacode+a.busi_tel1 as tel_num1,

a.busi_telareacode+a.busi_tel2 as tel_num2,

a.busi_telareacode+a.busi_tel3 as tel_num3,

(case when a.busi_telareacode<>'010' then '0'+a.busi_tel4 else a.busi_tel4 end) as tel_num4

from hp_accounts a join (select account_pk,case_pk,visitor_pk from hp_assignment where case_pk = 233 ) ha

on a.pk_id = ha.account_pk left join hp_contacts f on a.pk_id = f.account_pk where ha.visitor_pk is null

and a.auto_flag <> '1' order by account_id

)bb

過濾乙個查到的list相同的資料

網域名稱類問題 功能 過濾公升級過的網域名稱 之前北龍註冊的網域名稱都是通用 後來不對外註冊了,之前公升級的通用 都公升級為.國際網域名稱 在本資料庫裡,有些客戶公升級了一些,有些沒公升級。所以就要把資料過濾一下,開始腦子有點沒反應過來,後來自己畫了個圖,明白了。list biz方法 客戶id,條件...

mysql插入資料,獲取最新插入的ID(自增列)

在mysql中,使用auto increment型別的id欄位作為表的主鍵。通常的做法,是通過 select max id from tablename 的做法,但是顯然這種做法需要考慮併發的情況,需要在事務中對主表以 x鎖 待獲得max id 的值以後,再解鎖。這種做法需要的步驟比較多,有些麻煩,...

返回新插入資料的主鍵自增的值。

options usegeneratedkeys true,keyproperty instanceid keycolumn instance id options註解中預設設定的主鍵對應的欄位名為id 在我們的表中,主鍵名為instance id,因此需要將keyproperty和keycolum...