select max(c.c_physicsname) tableName from s_removeApply a,s_removearec b,s_usertable c where a.c_usertable_id=c.id group by b.c_rec_id我用上面的sql语句查询出一个结果tableName,我想使用这个结果 作为表名查询select * from tableName可以将这两个sql写成一条吗。。
select max(c.c_physicsname) tableName from s_removeApply a,s_removearec b,s_usertable c where a.c_usertable_id=c.id group by b.c_rec_id我用上面的sql语句查询出一个结果tableName,我想使用这个结果 作为表名查询select * from tableName可以将这两个sql写成一条吗。。
set @s=''
select @s=max(c.c_physicsname) tableName from s_removeApply a,s_removearec b,s_usertable c where a.c_usertable_id=c.id group by b.c_rec_id
exec('select * from '+@s)
select @tab=max(c.c_physicsname) tableName from s_removeApply a,s_removearec b,s_usertable c where a.c_usertable_id=c.id group by b.c_rec_id
set @sql='select * from '+@tab
exec (@sql)