zoukankan      html  css  js  c++  java
  • SQL Server 在数据库中查找字符串(不知道表名的情况下 查找字符串)

    declare @key varchar(30)
    set @key = '广州' --替换为要查找的字符串
    DECLARE @tabName VARCHAR(40),@colName VARCHAR(40)
    DECLARE @sql VARCHAR(2000)
    declare @tsql varchar(8000)
    DECLARE tabCursor CURSOR FOR
    SELECT name from ccfs3.dbo.sysobjects WHERE xtype = 'u' AND name <> 'dtproperties'
    OPEN tabCursor
    FETCH NEXT from tabCursor INTO @tabName
    WHILE @@fetch_status = 0
    BEGIN
    set @tsql = ''
    DECLARE colCursor CURSOR FOR Select Name from SysColumns Where id=Object_Id(@tabName) --and xtype=167
    OPEN colCursor
    FETCH NEXT from colCursor INTO @colName
    WHILE @@fetch_status = 0
    BEGIN
    SET @sql = 'if(exists(select * from ' + @tabName + ' where '
    SET @sql = @sql + @colName + ' like ''%' + @key + '%'')) begin select * from '
    set @sql = @sql + @tabName + ' where ' + @colName + ' like ''%' + @key + '%'';select '''
    + @tabName + ''' as TableName end'
    set @tsql = @tsql + @sql + ';'
    print @tsql
    FETCH NEXT from colCursor INTO @colName
    END
    exec(@tsql)
    CLOSE colCursor
    DEALLOCATE colCursor
    FETCH NEXT from tabCursor INTO @tabName
    END
    CLOSE tabCursor
    DEALLOCATE tabCursor

  • 相关阅读:
    等式
    Lemon 评测软件用法
    同花顺
    浅谈二分图的最大匹配和二分图的KM算法
    LCT总结
    5.30模拟赛
    树上斜率优化
    5.22 noip模拟赛
    KMP,HASH,Trie,AC自动机
    splay总结
  • 原文地址:https://www.cnblogs.com/a36040343/p/3625869.html
Copyright © 2011-2022 走看看