IF NOT EXISTS (?????????)
exec( 'create table [email protected][email protected]+ '(dt datetime,tag int,type int,mval real,mmax real,mmin real,mavg real,msum float )')
这样写如果不存在,[email protected][email protected](字符型+int)
------解决方案--------------------
- SQL code
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].[[email protected]+convert(varchar(10),@cury)+']'') and OBJECTPROPERTY(id, N''IsUserTable'') = 1)'
+' create table [email protected]+convert(varchar(10),@cury)+ '(dt datetime,tag int,type int,mval real,mmax real,mmin real,mavg real,msum float ) '
exec(@sql)
------解决方案--------------------
- SQL code
if not exists(select * from sys.sysobjects where id=object_ID(@[email protected]))exec( 'create table [email protected][email protected]+ '(dt datetime,tag int,type int,mval real,mmax real,mmin real,mavg real,msum float ) ')