怎么把下面语句的执行结果,插入到一个新表,再从原表把此记录删除
declare @n int
set @n= (select top 1 cno from tb321 where cno < 10 order by newid())
declare @strSql nvarchar(1000)
set @strSql='select top '+cast(@n as varchar) + 'cno,date,goods,cname,color long,size,quantity,price,year,range,season,category,brand from tb321 order by newid()'
exec(@strSql)
)
------解决方案--------------------
你再试试这样行吗;
--先建立一个表tb321_delete
select identity(int,1,1) as id,*
into tb321_delete
from tb321
where 1 <> 1
declare @n int
set @n= (select top 1 cno from tb321 where cno < 10 order by newid())
--没有用动态语句,直接用的查询
;with t
as
(
select top (@n) *
from tb321
order by newid() --随机获取数据
)
--删除随机数据,同时把结果保存到 tb321_delete
delete t
output deleted.* into tb321_delete