How can I read the value of a system environment variable in a T-SQL script?
This is to run on SQL Server 2005.
Thanks for the answers. They helped me get to a working solution, although this is probably not the most advanced method:
declare @val varchar(50)
create table #tbl (h varchar(50))
insert into #tbl exec master..xp_cmdshell 'echo %computername%'
set @val = (select top 1 h from #tbl)
drop table #tbl
Specifically I was trying to get the hostname, the echo %computername% could be replaced with the hostname system command. But this now works for any environment variable.