title: How to access any environment variable like %HOMEPATH% in SQL Server?
body: <p>Basically in my sql script , I want to create a database [DATABASE_NAME] by providing an explicit location to store its .mdf file? But the problem is, I must create the .mdf file in %HOMEPATH% directory i.e. C:/users/[username] and I cannot find a way to read an environment variable in sql. Is there any way I can write the script as</p>
  
  <pre><code>CREATE DATABASE [DATABASENAME] ON PRIMARY (NAME = 'DatabaseName',
  FILENAME = '%HOMEPATH%\DatabaseName.mdf' 
  </code></pre>