DATETIME SELECT SELECT INTO DATE PAD STRING DYNAMIC SQL CURSOR MONEY FORMAT PERCENT STORED PROCEDURE SQL SERVER AGENT JOB OPTIMIZATION WHILE LOOP OVER PARTITION BY UPDATE
SITE SEARCH SQLUSA.com HEADLINES NEWS
SQL E/BOOKS   SQL 2014 PROGRAMMING   DOWNLOADS
SCRIPTS SQL 2005 SQL 2008 ARTICLES
SQL JOBS TWITTER FORMAT VIDEOS
How to read an environment variable?

The following Microsoft SQL Server T-SQL code sample demonstrate how to read a Windows environment variable.

-- Display all environment variables

EXEC master..xp_cmdshell 'set'

------------

 

-- Retrieve a single environment variable - Read environment variable

DECLARE @EnvVar nvarchar(256)

CREATE TABLE #Upload(EnvVar nvarchar(256))

INSERT INTO #Upload

EXEC xp_cmdshell 'echo %USERDOMAIN%'

DELETE #Upload WHERE EnvVar is NULL OR EnvVar = ''

SET @EnvVar = (SELECT EnvVar from #Upload)

SELECT @EnvVar as [User Domain]

/* User Domain

ENTERPRISE */

DROP TABLE #Upload

------------

 

Related link: Setting Environment variables

 

 

Exam Prep 70-461
Exam 70-461
DATETIME SELECT SELECT INTO DATE PAD STRING DYNAMIC SQL CURSOR MONEY FORMAT PERCENT STORED PROCEDURE SQL SERVER AGENT JOB OPTIMIZATION WHILE LOOP OVER PARTITION BY UPDATE