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
  • 相关阅读:
    vue-cli3安装使用
    document.readyState
    js的堆与栈
    常用方法
    js常见排序算法
    微信小程序swiper高度问题
    微信小程序滑动菜单
    数据筛选和排序------的解析
    使用Windows实现数据绑定----------的解析
    实现Windoes程序的数据更新------的详细解析
  • 原文地址:https://www.cnblogs.com/mingyongcheng/p/2544745.html
Copyright © 2011-2022 走看看