<address id="xvfrz"></address>

              SQLSERVER 根据值查询表名

              CREATE PROCEDURE [dbo].[SP_FindValueInDB]
              (
              @value VARCHAR(1024)
              )
              AS
              BEGIN
              -- SET NOCOUNT ON added to prevent extra result sets from
              -- interfering with SELECT statements.
              SET NOCOUNT ON;
              DECLARE @sql VARCHAR(1024)
              DECLARE @table VARCHAR(64)
              DECLARE @column VARCHAR(64)
              CREATE TABLE #t (
              tablename VARCHAR(64),
              columnname VARCHAR(64)
              )
              DECLARE TABLES CURSOR
              FOR
              SELECT o.name, c.name
              FROM syscolumns c
              INNER JOIN sysobjects o ON c.id = o.id
              WHERE o.type = ‘U‘ AND c.xtype IN (167, 175, 231, 239)
              ORDER BY o.name, c.name
              OPEN TABLES
              FETCH NEXT FROM TABLES
              INTO @table, @column
              WHILE @@FETCH_STATUS = 0
              BEGIN
              SET @sql = ‘IF EXISTS(SELECT NULL FROM [‘ + @table + ‘] ‘
              SET @sql = @sql + ‘WHERE RTRIM(LTRIM([‘ + @column + ‘])) LIKE ‘‘%‘ + @value + ‘%‘‘) ‘
              SET @sql = @sql + ‘INSERT INTO #t VALUES (‘‘‘ + @table + ‘‘‘, ‘‘‘
              SET @sql = @sql + @column + ‘‘‘)‘
              EXEC(@sql)
              FETCH NEXT FROM TABLES
              INTO @table, @column
              END
              CLOSE TABLES
              DEALLOCATE TABLES
              SELECT *
              FROM #t
              DROP TABLE #t
              End

               

              --exec [SP_FindValueInDB] ‘aa‘

              相关文章
              相关标签/搜索
              2019年所有开马的记录 抚远县| 伊金霍洛旗| 高青县| 政和县| 东港市| 武宁县| 阳东县| 托克逊县| 耒阳市| 嘉兴市| 云霄县| 抚顺县| 开原市| 永仁县| 思茅市| 博兴县| 呼伦贝尔市| 永仁县| 余姚市| 霍山县| 广东省| 米林县| 西乌| 双流县| 宜州市| 郸城县| 丽水市| 鄂托克旗| 双桥区| 沧州市| 界首市| 武功县| 昔阳县| 平湖市| 清流县| 田东县| 武宁县| http://fa.hz0j2r4vo.fun http://fa.hz0j0r1vo.fun http://fa.hz0j0r2vo.fun http://fa.hz0j1r6vo.fun http://fa.hz0j2r9vo.fun