对于那些没有bbs 字段的表就报错!该加个什么条件呢?

解决方案 »

  1.   


    ...
    declare a_cursor cursor
    for
      select b.name from syscolumns a join sysobjects b on a.id=b.id where a.name='bbs' and b.xtype='U" and b.status>0
    open a_cursor
    ...
      

  2.   

    CREATE PROCEDURE del_col
    AS
    declare @a varchar(255)begindeclare a_cursor cursor for select d.name from syscolumns a,sysobjects d where a.id=d.id and d.xtype='U' and a.name='bbs'
    open a_cursor
    fetch   next from a_cursor into @a
    while @@Fetch_status=0
    begin
      Exec ('alter table  '+@a+'  DROP COLUMN  bbs ')
      fetch   next from a_cursor into @a
    endclose a_cursor
    deallocate a_cursorend
    GO