SQL选择表名称
数据库具有4个具有相同列的表,例如。 Salesjan,Salesfeb,Salesmarch,Salesapril。
我想在SQL Server或Report Builder中运行查询,我可以根据一个选择来更改表名,该选择将查询4个表中的一张。例如,在报告构建器中过滤器中的过滤器,
例如此
声明@tablename varchar(50) 设置@tableName ='test' 从@tableName中选择 *
A database had has 4 tables that has the same columns EG. SalesJAn, SalesFeb, SalesMarch, SalesApril.
I want to run a query in SQL server or in report builder Where i can change the table name based on a selection which one of 4 tables will be queried . Eg Filter in report builder
Like this
declare @tablename varchar(50)
set @tablename = 'test'
select * from @tablename
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
您可以创建一个过程,该过程将为给定的表名为选择。此过程看起来像这样:
然后您可以为所需的每个表名执行此过程。请参阅此处,根据您的描述:
”没有帮助您,请指出您仍然需要知道哪个。谢谢。
You can create a procedure which will do a select for a given table name. This procedure could look like this:
Then you can execute this procedure for every table name you want. Please see here an example according to your description: db<>fiddle
If this doesn't help you, please point out which exactly you still need to know. Thank you.