跟小D每日学口语

InfoSys SQL

create table #temp(Name varchar(50))--创建临时表  
insert #temp
select name from syscolumns where id=(select max(id) from sysobjects where xtype='u' and name='T_Staff')
select * from #temp
 declare @MyCursor CURSOR
 declare @Name nvarchar(50)
 set @MyCursor= CURSOR LOCAL SCROLL FOR   
               select [name] from #temp  where [Name]<>'Name'
               OPEN @MyCursor
               fetch next from @MyCursor into @Name
           while @@fetch_status=0
               begin  
   select cast(dbo.converttrim(@Name) as numeric(9,0)) as ColumnName from  dbo.T_Staff
          if(@@ERROR>0)
   begin
                   print @Name
    continue
   end
    fetch next from @MyCursor into @Name      
               end
            close @MyCursor
             deallocate @MyCursor
drop table #temp
posted @ 2009-09-13 23:30  Danny Chen  阅读(176)  评论(0编辑  收藏  举报