1

I have created a new environment variable VerName in my system. Tried to execute the batch file through SQL Server. The log file was not displaying anything. As part of debugging, I have revisited the logic and just wrote the below command to check whether the value is coming from the query

EXEC master..xp_cmdshell '%VerName%'

That was displaying the below error

'%VerName%' is not recognized as an internal or external command, operable program or batch file. NULL

Am I doing something wrong?

Krish
  • 166
  • 3
  • 13
  • 1
    Please take a look on [What is the reason for '...' is not recognized as an internal or external command, operable program or batch file?](https://stackoverflow.com/a/41461002/3074564) You should carefully read especially the chapter F which explains how environment variables are handled by Windows. – Mofi Aug 06 '18 at 10:06

1 Answers1

3

The environment variables will not be displayed as soon as you create them. I assume that you have created the Environment Variables and need to access them right away. It will not work in that way. Restart the SQL Server or restart the SQL Server Service. This will be resolved. Also please note that the debugging query you wrote will also not work. Please use the below query to debug properly

EXEC master..xp_cmdshell 'ECHO %VerName%'
  • 1
    Thanks!!. This worked. I restarted the service and the batch file is executing perfectly now. Thanks a ton!!! – Krish Aug 06 '18 at 10:52