You can get the[hostname]\[instancename] by:
SELECT @@SERVERNAME;
To get only the hostname when you have hostname\instance name format:
SELECT LEFT(ltrim(rtrim(@@ServerName)), Charindex('\', ltrim(rtrim(@@ServerName))) -1)
Alternatively as @GilM pointed out:
SELECT SERVERPROPERTY('MachineName')
You can get the actual IP address using this:
create Procedure sp_get_ip_address (@ip varchar(40) out)
as
begin
Declare @ipLine varchar(200)
Declare @pos int
set nocount on
set @ip = NULL
Create table #temp (ipLine varchar(200))
Insert #temp exec master..xp_cmdshell 'ipconfig'
select @ipLine = ipLine
from #temp
where upper (ipLine) like '%IP ADDRESS%'
if (isnull (@ipLine,'***') != '***')
begin
set @pos = CharIndex (':',@ipLine,1);
set @ip = rtrim(ltrim(substring (@ipLine ,
@pos + 1 ,
len (@ipLine) - @pos)))
end
drop table #temp
set nocount off
end
go
declare @ip varchar(40)
exec sp_get_ip_address @ip out
print @ip
출처 : http://stackoverflow.com/questions/142142/sql-query-to-get-servers-ip-address
'프로그램 경험 > Database' 카테고리의 다른 글
[SqlServer] 데이터에서 숫자만 빼고 특수문자들 제거 하기 (0) | 2014.07.31 |
---|---|
[SqlServer] SQL Server 2008 암호 저장 기능 안되는 미친 버그 (0) | 2014.07.08 |
[SqlServer] 키워드 'with' 근처의 구문이 잘못되었습니다. 이 문이 공통 테이블 식이거나, xmlnamespaces 절이거나, 변경 내용 추적 컨텍스트 절인 경우에는 이전 문을 세미콜론으로 종료해야 합니다. (0) | 2013.09.04 |
[SqlServer] OPENROWSET / OPENDATASOURCE (0) | 2013.07.19 |
[SqlServer] 키 자동증가 테이블에 명시적으로 키값 입력 하기 (0) | 2013.07.04 |