Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. Database & SysAdmin
  3. Database
  4. LinkedServer version

LinkedServer version

Scheduled Pinned Locked Moved Database
databasesharepointsql-serversysadminannouncement
2 Posts 2 Posters 4 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • D Offline
    D Offline
    Darrylw99
    wrote on last edited by
    #1

    I am trying to work through a table of linked server names to get their version and productversion Here is the code I'm using but I need to be able to get the values and use them elsewhere. I cannot get them into parameters. Also despite it populating the output with a list it isn't for each server. I mean its exactly the same info for every server. But its wrong its showing EG:

    Microsoft SQL Server 2017 (RTM) - 14.0.1000.169 (X64) Aug 22 2017 17:04:49 Copyright (C) 2017 Microsoft Corporation Express Edition (64-bit) on Windows 10 Enterprise 10.0 (Build 16299: )

    BUT should be

    Microsoft SQL Server 2012 (SP4-GDR) (KB4057116) - 11.0.7462.6 (X64)
    Jan 5 2018 22:11:56
    Copyright (c) Microsoft Corporation
    Standard Edition (64-bit) on Windows NT 6.1 (Build 7601: Service Pack 1) (Hypervisor)

    BEGIN
    DECLARE @srv SYSNAME, @db SYSNAME, @exec NVARCHAR(1024);
    DECLARE @serverName NVARCHAR(100)
    DECLARE @i INT = 1
    DECLARE @ServerCount INT=0
    DECLARE @retval nvarchar(1000)
    DECLARE @ParmDefinition nvarchar(500);
    DECLARE @sSQL nvarchar(500);

    SET @ServerCount = (SELECT COUNT(*) FROM SQLServerList.dbo.ListOfServers)
    SET @db = N'tempdb';

    WHILE (@i <= @ServerCount)
    BEGIN
    SET @serverName = (SELECT serverName FROM SQLServerList.dbo.ListOfServers where id = @i)
    IF @serverName IS NOT NULL
    BEGIN
    SET @exec = N'' + QUOTENAME(@serverName) + N'.' + N'' + QUOTENAME(@db) + N'.sys.sp_executesql ';

    		SELECT @sSQL = N'SELECT ''' + cast(@serverName as nvarchar) + ''',@@VERSION as version,SERVERPROPERTY(''ProductVersion'') AS ProductVersion  ';
    
    		SET @sSQL = @exec + ' ' + @sSQL
    		EXEC sp\_executesql @sSQL;
    
    	END		
    	SET @i = @i + 1			
    END	
    

    END

    M 1 Reply Last reply
    0
    • D Darrylw99

      I am trying to work through a table of linked server names to get their version and productversion Here is the code I'm using but I need to be able to get the values and use them elsewhere. I cannot get them into parameters. Also despite it populating the output with a list it isn't for each server. I mean its exactly the same info for every server. But its wrong its showing EG:

      Microsoft SQL Server 2017 (RTM) - 14.0.1000.169 (X64) Aug 22 2017 17:04:49 Copyright (C) 2017 Microsoft Corporation Express Edition (64-bit) on Windows 10 Enterprise 10.0 (Build 16299: )

      BUT should be

      Microsoft SQL Server 2012 (SP4-GDR) (KB4057116) - 11.0.7462.6 (X64)
      Jan 5 2018 22:11:56
      Copyright (c) Microsoft Corporation
      Standard Edition (64-bit) on Windows NT 6.1 (Build 7601: Service Pack 1) (Hypervisor)

      BEGIN
      DECLARE @srv SYSNAME, @db SYSNAME, @exec NVARCHAR(1024);
      DECLARE @serverName NVARCHAR(100)
      DECLARE @i INT = 1
      DECLARE @ServerCount INT=0
      DECLARE @retval nvarchar(1000)
      DECLARE @ParmDefinition nvarchar(500);
      DECLARE @sSQL nvarchar(500);

      SET @ServerCount = (SELECT COUNT(*) FROM SQLServerList.dbo.ListOfServers)
      SET @db = N'tempdb';

      WHILE (@i <= @ServerCount)
      BEGIN
      SET @serverName = (SELECT serverName FROM SQLServerList.dbo.ListOfServers where id = @i)
      IF @serverName IS NOT NULL
      BEGIN
      SET @exec = N'' + QUOTENAME(@serverName) + N'.' + N'' + QUOTENAME(@db) + N'.sys.sp_executesql ';

      		SELECT @sSQL = N'SELECT ''' + cast(@serverName as nvarchar) + ''',@@VERSION as version,SERVERPROPERTY(''ProductVersion'') AS ProductVersion  ';
      
      		SET @sSQL = @exec + ' ' + @sSQL
      		EXEC sp\_executesql @sSQL;
      
      	END		
      	SET @i = @i + 1			
      END	
      

      END

      M Offline
      M Offline
      Mycroft Holmes
      wrote on last edited by
      #2

      Check that the ID on the ServerList table is the same as i. i will be 1 then 2 then 3 etc I bet the ID field in servertables does not match. Try using a cursor and looping through the servertable.

      Never underestimate the power of human stupidity - RAH I'm old. I know stuff - JSOP

      1 Reply Last reply
      0
      Reply
      • Reply as topic
      Log in to reply
      • Oldest to Newest
      • Newest to Oldest
      • Most Votes


      • Login

      • Don't have an account? Register

      • Login or register to search.
      • First post
        Last post
      0
      • Categories
      • Recent
      • Tags
      • Popular
      • World
      • Users
      • Groups