选择所有表并过滤其数据

时间:2016-06-22 08:28:27

标签: sql-server

我正在创建一个搜索模块,它将显示来自不同表的数据,但我添加了一个功能,我可以搜索模块中的特定数据。

所有这些代码都有效,但我唯一的问题是如何实现select all tables names。

    SET @sql = ' ;WITH [ROWS] AS
    (

        SELECT ROW_NUMBER() OVER(ORDER BY '+@colname+' '+@dir_sort+') AS [ROW],
        COUNT (accno) OVER (PARTITION BY NULL) AS TOTAL_ROWS,
         accno, 
         accname, 
         add1, 
         zip, 
         dupload, 
         brdesc, 
         schcode
         FROM 'SELECT name from sys.tables where name like 'gen_048%'' <-- HERE IS MY PROBLEM

         where accno like ''%'+@accNum+'%'' or accname like ''%'+@accNum+'%'' or refdate + '''' + convert(varchar(10), refcount) like ''%'+@accNum+'%''

    )
SELECT
    *
FROM
    [ROWS]
WHERE
    [ROW] BETWEEN ('+cast(@page_num as varchar)+' - 1) * '+cast(@page_size as varchar)+' + 1 AND '+cast(@page_num as varchar)+' * '+cast(@page_size as varchar)+' '

exec( @sql)

0 个答案:

没有答案