allen
专注于java ee技术,包括struts,jsf,webwork,spring,hibernate,ibatis
posts - 7,  comments - 9,  trackbacks - 0
 Create   Proc   proc_insert   (@tablename   varchar(256))    
    as                                               --   表名称  
  begin    
      set   nocount   on  
          Declare   @sqlstr     varchar(4000),  
                          @sqlstr1   varchar(4000),  
                          @sqlstr2   varchar(4000)  
   
            Select   @sqlstr='select   ''Insert   '+@tablename    
   
                Select   @sqlstr1=   '   Values   (   ''+',       @sqlstr2='   ('  
   
                Select   @sqlstr1=@sqlstr1+col+'+'',''+'   ,@sqlstr2=@sqlstr2+name   +','   from(Select   case    
   
  --           when   a.xtype   =173   then   'case   when   '+a.name+'   is   null   then   ''NULL''   else   '+'convert(varchar('+convert(varchar(4),a.length*2+2)+'),'+a.name   +')'+'   end'  
   
                when   a.xtype   =104   then   'case   when   '+a.name+'   is   null   then   ''NULL''   else   '+'convert(varchar(1),'+a.name   +')'+'   end'  
   
                when   a.xtype   =175   then   'case   when   '+a.name+'   is   null   then   ''NULL''   else   '+'''''''''+'+'replace('+a.name+','''''''','''''''''''')'   +   '+'''''''''+'   end'  
   
                when   a.xtype   =61     then   'case   when   '+a.name+'   is   null   then   ''NULL''   else   '+'''''''''+'+'convert(varchar(23),'+a.name   +',121)'+   '+'''''''''+'   end'  
   
                when   a.xtype   =106   then   'case   when   '+a.name+'   is   null   then   ''NULL''   else   '+'convert(varchar('+convert(varchar(4),a.xprec+2)+'),'+a.name   +')'+'   end'  
   
                when   a.xtype   =62     then   'case   when   '+a.name+'   is   null   then   ''NULL''   else   '+'convert(varchar(23),'+a.name   +',2)'+'   end'  
   
                when   a.xtype   =56     then   'case   when   '+a.name+'   is   null   then   ''NULL''   else   '+'convert(varchar(11),'+a.name   +')'+'   end'  
   
                when   a.xtype   =60     then   'case   when   '+a.name+'   is   null   then   ''NULL''   else   '+'convert(varchar(22),'+a.name   +')'+'   end'  
   
                when   a.xtype   =239   then   'case   when   '+a.name+'   is   null   then   ''NULL''   else   '+'''''''''+'+'replace('+a.name+','''''''','''''''''''')'   +   '+'''''''''+'   end'  
   
                when   a.xtype   =108   then   'case   when   '+a.name+'   is   null   then   ''NULL''   else   '+'convert(varchar('+convert(varchar(4),a.xprec+2)+'),'+a.name   +')'+'   end'  
   
                when   a.xtype   =231   then   'case   when   '+a.name+'   is   null   then   ''NULL''   else   '+'''''''''+'+'replace('+a.name+','''''''','''''''''''')'   +   '+'''''''''+'   end'  
   
                when   a.xtype   =59     then   'case   when   '+a.name+'   is   null   then   ''NULL''   else   '+'convert(varchar(23),'+a.name   +',2)'+'   end'  
   
                when   a.xtype   =58     then   'case   when   '+a.name+'   is   null   then   ''NULL''   else   '+'''''''''+'+'convert(varchar(23),'+a.name   +',121)'+   '+'''''''''+'   end'  
   
                when   a.xtype   =52     then   'case   when   '+a.name+'   is   null   then   ''NULL''   else   '+'convert(varchar(12),'+a.name   +')'+'   end'  
   
                when   a.xtype   =122   then   'case   when   '+a.name+'   is   null   then   ''NULL''   else   '+'convert(varchar(22),'+a.name   +')'+'   end'  
   
                when   a.xtype   =48     then   'case   when   '+a.name+'   is   null   then   ''NULL''   else   '+'convert(varchar(6),'+a.name   +')'+'   end'  
   
  --           when   a.xtype   =165   then   'case   when   '+a.name+'   is   null   then   ''NULL''   else   '+'convert(varchar('+convert(varchar(4),a.length*2+2)+'),'+a.name   +')'+'   end'  
   
                when   a.xtype   =167   then   'case   when   '+a.name+'   is   null   then   ''NULL''   else   '+'''''''''+'+'replace('+a.name+','''''''','''''''''''')'   +   '+'''''''''+'   end'  
   
                else   '''NULL'''  
   
                end   as   col,a.colid,a.name  
   
                from   syscolumns   a   where   a.id   =   object_id(@tablename)   and   a.xtype   <>189   and   a.xtype   <>34   and   a.xtype   <>35   and     a.xtype   <>36  
   
                )t   order   by   colid  
     
                select   @sqlstr=@sqlstr+left(@sqlstr2,len(@sqlstr2)-1)+')   '+left(@sqlstr1,len(@sqlstr1)-3)+')''   from   '+@tablename  
     
                exec(   @sqlstr)  
   
                set   nocount   off  
   
  end  
   
 
GO
posted on 2007-03-06 15:41 robbin163 阅读(515) 评论(0)  编辑  收藏

只有注册用户登录后才能发表评论。


网站导航:
 

<2024年5月>
2829301234
567891011
12131415161718
19202122232425
2627282930311
2345678

常用链接

留言簿(3)

随笔分类

随笔档案

文章分类

文章档案

搜索

  •  

最新评论

阅读排行榜

评论排行榜