Print all characters before and after \ to find default and named instance name.
Copy and Paste the script
Run it
Print all characters before and after \ to find default and named instance name.
Copy and Paste the script
Run it
Declare @servername sysname, @len INT, @i INT, @Left varchar(max), @right varchar(max) SET @SERVERNAME = (SELECT @@servername); --SELECT @SERVERNAME AS [SERVER NAME]; IF @SERVERNAME like '%\%' BEGIN SET @Left= (select Left(@SERVERNAME, charindex('\', @SERVERNAME) - 1)) SELECT @Left AS [DEFAULT SERVER NAME] SET @len = (SELECT LEN(@SERVERNAME)) --SELECT @LEN SET @right = (SELECT SUBSTRING(@SERVERNAME,Charindex ('\', @SERVERNAME)+1,@len)) SELECT @right AS [SQL INSTANCE NAME] END ELSE BEGIN SELECT @left = @SERVERNAME SELECT @Left AS [DEFAULT SERVER NAME] SELECT @right = 'DEFAULT' SELECT @right AS [SQL INSTANCE NAME] END