Чтобы определить конкретную переменную среды в T-SQL (MS SQL Server), вы можете сделать что-то вроде:
Предоставление разрешений безопасности
use [master]
execute sp_configure 'show advanced options', 1
reconfigure
go
execute sp_configure 'xp_cmdshell', 1
reconfigure
go
grant execute on xp_cmdshell to [DOMAIN\UserName]
grant control server to [DOMAIN\UserName]
go
Источник: https://stackoverflow.com/a/13605864/601990
Использовать переменные среды
-- name of the variable
declare @variableName nvarchar(50) = N'ASPNETCORE_ENVIRONMENT'
-- declare variables to store the result
declare @environment nvarchar(50)
declare @table table (value nvarchar(50))
-- get the environment variables by executing a command on the command shell
declare @command nvarchar(60) = N'echo %' + @variableName + N'%';
insert into @table exec master..xp_cmdshell @command;
set @environment = (select top 1 value from @table);
-- do something with the result
if @environment = N'Development' OR @environment = N'Staging'
begin
select N'test code'
end
else
begin
select N'prod code'
end
Также не забудьте перезапустить службу SQL Server при изменении переменных среды.