While executing some query, sometimes it is required to have the Client's IP Address who is executing this Query.
SELECT client_net_addressFROM sys.dm_exec_connectionsWHERE session_id = @@SPID;
We can also put this Query into some function which can be used further.
CREATE FUNCTION [dbo].[GetCurrentIP] ()RETURNS varchar(255)ASBEGIN
DECLARE @IP_Address varchar(255);
SELECT @IP_Address = client_net_address FROM sys.dm_exec_connections
WHERE Session_id = @@SPID;