Answer the question
In order to leave comments, you need to log in
Is it possible to access a table in a nested select in where without knowing its name?
select some_column_name
from some_table
where some_column_name < (select max(some_column_name) from some_table)
-- как в этом месте узнать и/или указать имя или ссылку или какой-то алиас для some_table
Answer the question
In order to leave comments, you need to log in
Start with:
SELECT sys.tables.[name] AS 'TableName',
sys.columns.[name] AS 'ColumnName'
FROM sys.columns
INNER JOIN sys.tables ON sys.columns.object_id = sys.tables.object_id
WHERE sys.columns.[name] LIKE '%ID%'
ORDER BY 1, 2
WHERE 1=1 ORDER BY some_column_name DESC OFFSET 1 ROWS
How to address select with a table object
DECLARE @SQL VARCHAR(MAX) = 'SELECT * FROM '
SELECT @SQL = @SQL + sys.tables.[name] FROM sys.columns
INNER JOIN sys.tables ON sys.columns.object_id = sys.tables.object_id
WHERE sys.columns.[name] = 'some_column_name'
EXECUTE( @SQL )
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question