October 16, 2024 at 10:03 am
How do I use a variable name for a linked server name in a linked server query?
set @servername = (SELECT TOP (1) [ServerName]
FROM [Database].[dbo].[Servers]
declare @servername =
SELECT * FROM [SERVER_NAME].[DATABASE_NAME].[SCHEMA_NAME].[TABLE_NAME]
SELECT * FROM [@servername ].[DATABASE_NAME].[SCHEMA_NAME].[TABLE_NAME]
Ideally how can I backup all servers/databases onto a single fileshare from a single server as a sqljob ?One server will be chosen from this query SELECT TOP (1) [ServerName]
FROM [Database].[dbo].[Servers] every time the sqljob runs.
October 16, 2024 at 12:12 pm
Dynamic SQL is one way of creating a variable SELECT statement that can be executed.
The absence of evidence is not evidence of absence.
Martin Rees
You can lead a horse to water, but a pencil must be lead.
Stan Laurel
Viewing 2 posts - 1 through 1 (of 1 total)
You must be logged in to reply to this topic. Login to reply