Posted by Erland Sommarskog on 10/08/91 11:27
calan (none@nospam.com) writes:
> So back to the original question, is there an SQL example of this? I'm
> not having any luck finding anything on using a subquery in a FROM
> clause that returns a list of table names.
And you will never have. There is no indirection on table names in T-SQL.
In fact there is very little indirection at all in T-SQL. And for a good
reason.
> I thought something simple like this would work (This assumes that all
> tables listed in "MyTables" will have a field called "Configured".):
>
> SELECT t2.TableName, t1.Configured
> FROM (SELECT TableName FROM MyTables AS t2) t1
>
> But it doesn't....
Either you loop that table and build the list with dynamic SQL, or
you hard-code each table. I would recommend the latter.
--
Erland Sommarskog, SQL Server MVP, esquel@sommarskog.se
Books Online for SQL Server SP3 at
http://www.microsoft.com/sql/techinfo/productdoc/2000/books.asp
[Back to original message]
|