How to find SERVER NAME and LOCAL MACHINE Name in SQL Server ?

Posted by Sarvesh under Sql Server on 10/22/2009 | Views : 115662 | Status : [Member] | Replies : 2
hi experts

I want to findout "Server Name of the SQL Server Installed" and "Machine Name of where the sql server get connected(Client)". Becoze, These information are required inside my stored procedure.

very urgent please

thanks in advance
sarvesh




Responses

Posted by: Pandians on: 10/22/2009 [Member] [MVP] Silver

Up
0
Down
Good Day

1. To findout "SERVER NAME"
SELECT SERVERPROPERTY('MACHINENAME')

2. To findout "SERVER NAME" with "INSTANCE NAME" (If its Named Instance)
SELECT SERVERPROPERTY('SERVERNAME')

3. To findout "CLIENT MACHINE NAME"(Local Machine Name)
SELECT HOST_NAME()

I think this reply would help you.

Cheers

Cheers
www.SQLServerbuddy.blogspot.com
iLink Multitech Solutions

Sarvesh, if this helps please login to Mark As Answer. | Alert Moderator

Posted by: Tridev_2005 on: 10/22/2009 [Member] Starter

Up
0
Down
multiple way to find server name

-Windows computer name on which the server instance is running.

-For a clustered instance, an instance of SQL Server running on a virtual server on Microsoft Cluster Service, it returns the name of the virtual server.

-NULL = Input is not valid, or an error.

SELECT SERVERPROPERTY('MachineName') AS MachineName


GO




-Both the Windows server and instance information associated with a specified instance of SQL Server.

SELECT SERVERPROPERTY('ServerName') AS ServerName


GO



-NetBIOS name of the local computer on which the instance of SQL Server is currently running.

-For a clustered instance of SQL Server on a failover cluster, this value changes as the instance of SQL Server fails over to other nodes in the failover cluster.

-On a stand-alone instance of SQL Server, this value remains constant and returns the same value as the MachineName property.

Select SERVERPROPERTY('ComputerNamePhysicalNetBIOS') as PhysicalName


Go




-Returns the name of the local server running SQL Server.

SELECT @@SERVERNAME AS ServerNameGlobalVar

GO


Sarvesh, if this helps please login to Mark As Answer. | Alert Moderator

Login to post response