July 26, 2017 at 11:51 am
I am trying to execute the command in the other server which are linked. EXEC @retVal = sp_executesql @dml; statement giving me the database name. But I can't hold it in a variable for my level of checks. Can yu suggest how to modify the script?
DECLARE @dml nvarchar(max) = N''SELECT @dml += 'SELECT name FROM ' + QUOTENAME(@linkedserverName) +
'.[master].[sys].databases WHERE name = ''' + @DBname + ''' AND state_desc! = ''ONLINE'''
SELECT @dml as string
--exec(@dml)
Declare @retVal SYSNAME;
EXEC @retVal = sp_executesql @dml;
DECLARE @vi nVARCHAR(1000)
DECLARE @vQuery nVARCHAR(1000)
SET @vQuery = (select @dml);
select @vQuery
declare @i nvarchar(1000);
exec sp_executesql @vQuery, N'@i nvarchar(1000) output', @i output
select @i
Thanks.
July 26, 2017 at 12:06 pm
SQL-DBA-01 - Wednesday, July 26, 2017 11:51 AMI am trying to execute the command in the other server which are linked. EXEC @retVal = sp_executesql @dml; statement giving me the database name. But I can't hold it in a variable for my level of checks. Can yu suggest how to modify the script?
DECLARE @dml nvarchar(max) = N''SELECT @dml += 'SELECT name FROM ' + QUOTENAME(@linkedserverName) +
'.[master].[sys].databases WHERE name = ''' + @DBname + ''' AND state_desc! = ''ONLINE'''SELECT @dml as string
--exec(@dml)
Declare @retVal SYSNAME;EXEC @retVal = sp_executesql @dml;
DECLARE @vi nVARCHAR(1000)
DECLARE @vQuery nVARCHAR(1000)SET @vQuery = (select @dml);
select @vQuery
declare @i nvarchar(1000);
exec sp_executesql @vQuery, N'@i nvarchar(1000) output', @i output
select @i
I write a fair amount of dynamic SQL, but I am really not sure what you are attempting to accomplish or what you are expecting to be returned. With a cursory look I question your last sp_executesql statement. Perhaps if you provide a better explaination of what you are trying to accomplish and what you are looking to have returned we could provide better answers.
July 26, 2017 at 12:13 pm
Lynn Pettis - Wednesday, July 26, 2017 12:06 PMSQL-DBA-01 - Wednesday, July 26, 2017 11:51 AMI am trying to execute the command in the other server which are linked. EXEC @retVal = sp_executesql @dml; statement giving me the database name. But I can't hold it in a variable for my level of checks. Can yu suggest how to modify the script?
DECLARE @dml nvarchar(max) = N''SELECT @dml += 'SELECT name FROM ' + QUOTENAME(@linkedserverName) +
'.[master].[sys].databases WHERE name = ''' + @DBname + ''' AND state_desc! = ''ONLINE'''SELECT @dml as string
--exec(@dml)
Declare @retVal SYSNAME;EXEC @retVal = sp_executesql @dml;
DECLARE @vi nVARCHAR(1000)
DECLARE @vQuery nVARCHAR(1000)SET @vQuery = (select @dml);
select @vQuery
declare @i nvarchar(1000);
exec sp_executesql @vQuery, N'@i nvarchar(1000) output', @i output
select @iI write a fair amount of dynamic SQL, but I am really not sure what you are attempting to accomplish or what you are expecting to be returned. With a cursory look I question your last sp_executesql statement. Perhaps if you provide a better explaination of what you are trying to accomplish and what you are looking to have returned we could provide better answers.
Trying to check of the database is present in another node
Of always on. If it's present but not online, say restoring drop it.
Thanks.
July 26, 2017 at 12:23 pm
Sorry, too old to do word problems. What are you expecting to be returned by the query (queries) you are running.
July 26, 2017 at 12:27 pm
Alright. I just fixed it.
Thanks.
July 26, 2017 at 4:54 pm
SQL-DBA-01 - Wednesday, July 26, 2017 12:27 PMAlright. I just fixed it.
Two way street here... So what did you end up doing?
--Jeff Moden
Change is inevitable... Change for the better is not.
Viewing 6 posts - 1 through 5 (of 5 total)
You must be logged in to reply to this topic. Login to reply