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

  • 相关阅读:
    循环链表问题
    非常有用的编程学习网站
    我的单例模式(C++)
    C# xml解析
    设计模式趣解
    简单工厂(C++)
    贝塞尔曲线 原理
    C++ 1.#QNAN0;1.#QNAN0
    [NOI2018]屠龙勇士 excrt
    [NOI.AC#30]candy 贪心
  • 原文地址:https://www.cnblogs.com/a36040343/p/3625869.html
Copyright © 2011-2022 走看看