zoukankan      html  css  js  c++  java
  • 动态执行sql

    -- =============================================
    -- Declare and using a KEYSET cursor
    -- =============================================
    drop proc pro_eachsql
    go
    create proc pro_eachsql @sqlTo nvarchar(max)
    as
    begin


     create table #table_sql ( /* Temp command storage */  
      exesql    nvarchar(max) COLLATE database_default NULL  
     )  


     set nocount on  
     print 'insert #table_sql '+@sqlTo
     exec('insert #table_sql '+@sqlTo)

    DECLARE  sqllist_cursor CURSOR
    KEYSET
    FOR select * from #table_sql
    DECLARE @sql nvarchar(max)
    OPEN sqllist_cursor
    FETCH NEXT FROM sqllist_cursor INTO @sql
    WHILE (@@fetch_status <> -1)
    BEGIN
        IF (@@fetch_status <> -2)
        BEGIN
    --        PRINT 'add user defined code here' 
    --        eg.
            exec(@sql)
        END
        FETCH NEXT FROM sqllist_cursor INTO @sql
    END
    drop table #table_sql
    CLOSE sqllist_cursor
    DEALLOCATE sqllist_cursor

    end
    GO
    pro_eachsql 'select ''print ''''''+name+'''''''' from sys.tables'


    select ''print ''''''+name+'''''''' from sys.tables
  • 相关阅读:
    iOS 检测版本更新(02)
    iOS开发之检查更新
    Core Location :⽤用于地理定位
    TCP与UDP区别
    iOS设计模式之观察者模式
    联系人案例
    ksoap调用webservice
    Android获取内置sdcard跟外置sdcard路径
    百度sdk定位不成功,关闭定位
    PinnedHeaderListView实现删除
  • 原文地址:https://www.cnblogs.com/mingyongcheng/p/2544745.html
Copyright © 2011-2022 走看看