日期:2014-05-17 浏览次数:20486 次
use pubs
if exists (select * from dbo.sysobjects where id = object_id(N'[dbo].[testxxx]') and OBJECTPROPERTY(id, N'IsUserTable') = 1)
begin
insert into testxxx
select * from authors
end
else
begin
select * into testxxx from authors
end
use pubs
go
declare @tbname nvarchar(20),@sql nvarchar(4000)
select @tbname='test'+replace(replace(replace(convert(varchar(17),getdate(),120),'-',''),' ',''),':','')
if exists (select * from dbo.sysobjects where id = object_id(@tbname) and OBJECTPROPERTY(id, N'IsUserTable') = 1)
set @sql='insert into '+@tbname+' select * from authors'
else
set @sql='select * into '+@tbname+' from authors'
execute(@sql)