if Exists(select * from tempdb..sysobjects where name = '#tempTbl1')
print '存在'
else
print '不存在'

解决方案 »

  1.   

    if object_id(tempTbl ) is not null
     insert into #tempTbl select * from 表1 where 字段1='a'
    else
     select * into #tempTbl from 表1 where 字段1='b'
      

  2.   

    if object_id('tempdb..#tempTbl') is not null
     insert #tempTbl select * from 表1 where 字段1='a'
    else
     select * into #tempTbl from 表1 where 字段1='b'
      

  3.   

    pengdali(大力 V3.0) 厉害!
      

  4.   

    if object_id('tempdb..temptablename') is not null
    print 'exists'
      

  5.   

    if object_id('tempdb..#tempTbl') is not null
     insert #tempTbl select * from 表1 where 字段1='a'
    else
     select * into #tempTbl from 表1 where 字段1='b'
      

  6.   

    if object_id('tempdb..#tempTbl') is not null
    print '存在'
    else
    print '不存在'
      

  7.   

    上面的做法是正确的,可是当表中存在一个标识列时,insert #tempTbl select * from 表1 where 字段1='a'提示:
       仅当使用了列的列表,并且 IDENTITY_INSERT 为 ON 时,才能在表 '#temptbl' 中为标识列 指定显式值。