I think I found a solution for my problem
SET NOCOUNT ON
DECLARE @userHost varchar(50)
DECLARE @hostName varchar(50)
DECLARE @result bit
CREATE TABLE #sp_who2
(
SPID INT,
Status VARCHAR(1000) NULL,
Login SYSNAME NULL,
HostName SYSNAME NULL,
BlkBy SYSNAME NULL,
DBName SYSNAME NULL,
Command VARCHAR(1000) NULL,
CPUTime INT NULL,
DiskIO INT NULL,
LastBatch VARCHAR(1000) NULL,
ProgramName VARCHAR(1000) NULL,
SPID2 INT,
REQUESTEID INT
)
INSERT INTO #sp_who2
EXEC sp_who2
select @userHost = HostName from #sp_who2 where spid = @@SPID
SET @hostName = SUBSTRING(@@servername, 0, charindex('\', @@servername))
SET @hostName = LTRIM(RTRIM(@hostname))
IF (LTRIM(RTRIM(@userHost)) = @hostName )
BEGIN
SET @result = 1
END
ELSE
BEGIN
SET @result = 0
END
SELECT @result
Or does anyone know of a better way?
Thank you