title: Log Batch File Status/Timings to SQL Server
body: <p>I would like to enhance an existing bat file to log execution duration to a SQL Server table. The current bat file has a single line that calls a command line utility.</p>
  
  <p>I thought I would leverage something like this, <a href="https://stackoverflow.com/questions/389844/sql-statements-in-a-windows-batch-file">SQL Statements in a Windows Batch File</a>.  Pseudo code:</p>
  
  <pre><code>StartTime = Now()
  hyperioncommandlineshell.cmd /a:parm1 /b:parm2 /c:parm3
  sqlcmd.exe -b -S myhost -E -d mydatabase -Q "Insert Into MyTable Values (Current_Timestamp, 'MyProcess', Now() - StartTime)" -W    
  </code></pre>
  
  <p>Some questions:</p>
  
  <ol>
  <li><p>The server that this bat file runs on doesn't have the SQL tools, and I see from <a href="http://www.sqlservercentral.com/Forums/Topic1050391-391-1.aspx" rel="nofollow noreferrer">this</a> post that it does require an installation (you can't just copy over the <code>sqlcmd.exe</code> file). This will meet with resistance. Is there another way to execute a SQL statement from a batch file without having to install software?</p></li>
  <li><p>I don't have experience with BAT files. Can someone provide guidance on how to get the duration of a process (like grabbing the start time, and calculating the difference at the end)?</p></li>
  </ol>
  
  <p>I would probably try using another tool I'm more familiar with, but I'm trying to do this in bat so that the change only affects one existing object, and doesn't require additional objects.</p>