根据表中数据生成insert语句的存储过程

<script type="text/javascript"><!-- google_ad_client = "pub-2947489232296736"; /* 728x15, 创建于 08-4-23MSDN */ google_ad_slot = "3624277373"; google_ad_width = 728; google_ad_height = 15; //--> </script> <script type="text/javascript" src="http://pagead2.googlesyndication.com/pagead/show_ads.js"> </script>
<script type="text/javascript"><!-- google_ad_client = "pub-2947489232296736"; /* 160x600, 创建于 08-4-23MSDN */ google_ad_slot = "4367022601"; google_ad_width = 160; google_ad_height = 600; //--> </script><script type="text/javascript" src="http://pagead2.googlesyndication.com/pagead/show_ads.js"> </script>

有个缺点……就是标识种子的列也insert

CREATE  procspGeninsertSQL(@tablenamevarchar(256))

as

begin

declare@sqlvarchar(8000)

declare@sqlValuesvarchar(8000)

set@sql='('

set@sqlValues='values(''+'

select@sqlValues=@sqlValues+cols+'+'',''+',@sql=@sql+'['+name+'],'

 from

     (selectcase

               whenxtypein(48,52,56,59,60,62,104,106,108,122,127)                               

                    then'casewhen'+name+'isnullthen''NULL''else'+'cast('+name+'asvarchar)'+'end'

               whenxtypein(58,61)

                    then'casewhen'+name+'isnullthen''NULL''else'+'''''''''+'+'cast('+name+'asvarchar)'+'+'''''''''+'end'

              whenxtypein(167)

                    then'casewhen'+name+'isnullthen''NULL''else'+'''''''''+'+'replace('+name+','''''''','''''''''''')'+'+'''''''''+'end'

               whenxtypein(231)

                    then'casewhen'+name+'isnullthen''NULL''else'+'''N''''''+'+'replace('+name+','''''''','''''''''''')'+'+'''''''''+'end'

               whenxtypein(175)

                    then'casewhen'+name+'isnullthen''NULL''else'+'''''''''+'+'cast(replace('+name+','''''''','''''''''''')asChar('+cast(lengthasvarchar) +'))+'''''''''+'end'

               whenxtypein(239)

                    then'casewhen'+name+'isnullthen''NULL''else'+'''N''''''+'+'cast(replace('+name+','''''''','''''''''''')asChar('+cast(lengthasvarchar) +'))+'''''''''+'end'

               else'''NULL'''1
<script type="text/javascript"><!-- google_ad_client = "pub-2947489232296736"; /* 728x15, 创建于 08-4-23MSDN */ google_ad_slot = "3624277373"; google_ad_width = 728; google_ad_height = 15; //--> </script> <script type="text/javascript" src="http://pagead2.googlesyndication.com/pagead/show_ads.js"> </script>
<script type="text/javascript"><!-- google_ad_client = "pub-2947489232296736"; /* 160x600, 创建于 08-4-23MSDN */ google_ad_slot = "4367022601"; google_ad_width = 160; google_ad_height = 600; //--> </script><script type="text/javascript" src="http://pagead2.googlesyndication.com/pagead/show_ads.js"> </script>
阅读更多
文章标签: insert 存储 null sql
个人分类: 数据库
想对作者说点什么? 我来说一句

没有更多推荐了,返回首页

加入CSDN,享受更精准的内容推荐,与500万程序员共同成长!
关闭
关闭