使用存储过程中的表名填充数据集

问题描述:

我有一个存储过程,可以返回多个表.

I have a stored procedure that returns multiple tables.

它正确填充了我的数据集,但是命名了我的表[TableTable1Table2,...].

It populates my dataset correctly but it names my tables [Table,Table1,Table2,...].

我可以在数据库层中添加一些东西(到存储过程中)以正确命名表吗?

Is there something I can add in the database layer (to my stored procedure) that will name the tables properly?

您的SP实际上没有返回多张表,而是从表中返回了对列和行的选择,因此没有表名",因此为什么它们的名称分别为table1,table2等.如果它很重要,则可以为每个选择返回一个额外的列,并在该列中填充所需的名称,然后从那里开始使用它.

Your SP is not actually returning multiple tables, its returning a selection of columns and rows from your tables, therefore there is no 'table name', and hence why they are named table1, table2 etc. If its important, you could return an extra column for each selection, and in that column fill it with the desired name and then use it from there.

   select *,'MyTableName1' As [TableName] name from mytablename1
   select *,'MyTableName2' As [TableName] name from mytablename2