日期:2014-05-18 浏览次数:20473 次
if object_id('数据库名..表名') is not null drop table 表名 else create table .... go
------解决方案--------------------
declare @tb varchar(10)
declare @curY int
declare @sql varchar(1000)
select @tb='a'
select @cury=1
select @sql='if not exists (select * from dbo.sysobjects where id = object_id(N''[dbo].['+@tb+convert(varchar(10),@cury)+']'') and OBJECTPROPERTY(id, N''IsUserTable'') = 1)'
+' create table '+@tb+convert(varchar(10),@cury)+ '(dt datetime,tag int,type int,mval real,mmax real,mmin real,mavg real,msum float ) '
exec(@sql)
------解决方案--------------------
if not exists(select * from sys.sysobjects where id=object_ID(@tb+@curY)) exec( 'create table '+@tb+@curY+ '(dt datetime,tag int,type int,mval real,mmax real,mmin real,mavg real,msum float ) ')