Using Environment variables in T-SQL

前端 未结 6 1822
独厮守ぢ
独厮守ぢ 2021-01-18 16:31

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

This is to run on SQL Server 2005.

6条回答
  •  栀梦
    栀梦 (楼主)
    2021-01-18 17:10

    xp_cmdshell is generally best avoided for security reasons.

    You're better off using a CLR assembly. Here's a good introduction to creating a CLR assembly.

    You can use System.Environment.GetEnvironmentVariable() in C# - you'll find more info on how to do that here.

提交回复
热议问题