This request
SELECT TOP 1 '[' + Name + '].[dbo].[AMT]' as name FROM master.sys.databases where name like 'CC_%R' outputs one line [CC_..._58R].[dbo].[AMT] . This line is the name of the current table that I need to work with. I need to substitute this line in the FROM field of my query. The request should not be a function, a trigger, a program, etc. I tried to do this:
with R as (SELECT TOP 1 '[' + Name + '].[dbo].[AMT]' as name FROM master.sys.databases where name like 'CC_%R') SELECT * FROM R but this is not correct, since R is a table, not a string.
I am writing the request in Microsoft SQL Server Management Studio (Microsoft SQL Server 2014).