Reputation: 2237
I'm not very perfect in SQL. but I've got a scenario where I need to get data from the table which is the result of another query.
something like this:
select * from (select top 1 col from tableA)
where top 1 col
contains the table name.
Sample data:
tableA:
col
tableB
tableB:
col
1
Upvotes: 0
Views: 1815
Reputation: 1264
DECLARE @sql NVARCHAR(200);
SELECT TOP 1 @sql = 'SELECT * FROM ' + col FROM tableA
EXECUTE sp_executesql @sql
Upvotes: 3