Skip to content
Advertisement

Using Environment variables in T-SQL

How can I read the value of a system environment variable in a T-SQL script?

This is to run on SQL Server 2005.

Advertisement

Answer

This should give you a list (provided you allow people to execute xp_cmdshell)

exec master..xp_cmdshell ‘set’

Note: xp_cmdshell is a security hazard …

You could also do this with a managed stored proc an extended stored proc or via a com component.

User contributions licensed under: CC BY-SA
1 People found this is helpful
Advertisement