DECLARE @PortNumber VARCHAR(10), @KeyValue VARCHAR(100)
IF CHARINDEX('\',@@SERVERNAME,0) <>0
BEGIN
SET @KeyValue = 'SOFTWARE\MICROSOFT\Microsoft SQL Server\'+@@SERVICENAME+'\MSSQLServer\Supersocketnetlib\TCP'
END
ELSE
BEGIN
SET @keyValue = 'SOFTWARE\MICROSOFT\MSSQLServer\MSSQLServer \Supersocketnetlib\TCP'
END
--How to read Registry in T-SQL Terms - ROOTKEY, KEY, VALUENAME,VALUE
EXEC master..xp_regread 'HKEY_LOCAL_MACHINE',@KeyValue,'Tcpport',@value=@PortNumber OUTPUT
SELECT 'SQLSERVER_NAME: '+@@SERVERNAME + ' : SQL SERVER Port Number:'+CONVERT(VARCHAR(10),
@PortNumber)
Leave a Reply