insert into hfgl_Hffpd(comname,tasktypename,sendman,activitynumber,zysj,createtime,Customername,address,
phonenumber,custermercode,tasktype)
select top 30 percent * from(
SELECT ROW_NUMBER() OVER(ORDER BY z.createtime DESC) AS ROWNUM,
cp.comname,dt.tasktypename,t.sendman,t.taskcode,z.zysj,z.createtime,c.customername,c.address,c.phonenumber,
c.customercode,dt.tasktype
from zyhd_gdrqjmdhZyd z
LEFT JOIN task t ON z.rwdid=t.id
LEFT JOIN customer c ON t.customerid=c.ID
left join company cp on t.recievecom=cp.id
join dic_tasktype dt on t.tasktypeid=dt.tasktype
where 1=1)h where datediff(dd,h.createtime,getdate())=2
------解决方案--------------------
INSERT INTO hfgl_Hffpd
( comname ,
tasktypename ,
sendman ,
activitynumber ,
zysj ,
createtime ,
Customername ,
address ,
phonenumber ,
custermercode ,
tasktype
)
SELECT TOP 30 PERCENT
comname ,
tasktypename ,
sendman ,
activitynumber ,
zysj ,
createtime ,
Customername ,
address ,
phonenumber ,
custermercode ,
tasktype
FROM ( SELECT ROW_NUMBER() OVER ( ORDER BY z.createtime DESC ) AS ROWNUM ,
cp.comname ,
dt.tasktypename ,
t.sendman ,
t.taskcode ,
z.zysj ,
z.createtime ,
c.customername ,
c.address ,
c.phonenumber ,
c.customercode ,
dt.tasktype
FROM zyhd_gdrqjmdhZyd z
LEFT JOIN task t ON z.rwdid = t.id
LEFT JOIN customer c ON t.customerid = c.ID
LEFT JOIN company cp ON t.recievecom = cp.id