IF NOT EXISTS (?????????)
exec( 'create table  '+@tb+@curY+ '(dt datetime,tag int,type int,mval real,mmax real,mmin real,mavg real,msum float )')
这样写如果不存在,就创建表 @tb+@curY(字符型+int)

解决方案 »

  1.   


    if object_id('数据库名..表名') is not null
       drop table 表名
    else
       create table ....
    go
      

  2.   

    IF NOT EXISTS (?????????) 
    exec(  'create table   '+@tb+@curY+  '(dt datetime,tag int,type int,mval real,mmax real,mmin real,mavg real,msum float ) ') 
    怎样写? 如果不存在,就创建表 @tb+@curY(字符型+int)
      

  3.   

    if object_id('数据库名..表名') is not null
       --drop table 表名 --这句不要就行了.
    else
       create table ....
    go或者
    if object_id('数据库名..表名') is null
       create table .......
      

  4.   

    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)
      

  5.   


    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 ) ')