当前位置: 代码迷 >> Sql Server >> 怎么实现表名的模糊查询后,实现字段查询
  详细解决方案

怎么实现表名的模糊查询后,实现字段查询

热度:30   发布时间:2016-04-24 09:08:29.0
如何实现表名的模糊查询后,实现字段查询
如题,

如何根据“%***%”查询了几张表后,在根据字段[日期],[成交额]查询数据


------解决思路----------------------
select  b.*
from (select * from a) b
where b.[] = ?
------解决思路----------------------
declare @searchTables nvarchar(100) = '%0000%'
declare @sqlCommand nvarchar(4000) = ''
declare @date varchar(10) = '1900.01.01'
declare @turnover varchar(100) = '45000'

;with tableNames as
(
select top 2 'select * from ' + Name + 'where 日期 = ''' + @date + ''' and 成交额 = ' + @turnover + ' go ' as SelectTable from sys.tables
where name like @searchTables
)
select @sqlCommand = @sqlCommand + SelectTable from tableNames

exec (@sqlCommand)
  相关解决方案