sql 模糊查詢表名后再查詢該表的數據


項目中有很多表,表名都是“id+2019”,我的思路是先查詢表名select name  from sys.tables where name like 'id%';

再查詢tablename=name這張表數據,具體實現是:

 

declare @tbname varchar(100)

select @tbname=name from sys.tables where name like 'id%';

exec('select * from '+@tbname')

 

-----------------------------------------------------------------

declare @tbname varchar(20)
select @tbname=name from sys.tables where name like '歷史記錄_%71_2019'
Exec('select top 100 * from ' +@tbname)


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM