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