In SQL Server, I'm trying to find all of the tables that contain a certain account number. Many of the tables, use the column name 'account'. And I'm trying to find all of the tables where account = '123'.
I'm using the following code to get all of the tables by name, and I already know the column name, but I can't seem to be able to use the table name from the results.
select * from
(
SELECT
sys.columns.name AS ColumnName,
tables.name AS TableName
FROM
sys.columns
JOIN sys.tables ON
sys.columns.object_id = tables.object_id
WHERE
sys.columns.name = 'account'
) as tn
where TableName.account = '123'