title: How to store SQL query result in a local variable of batch file?
body: <p>I am using following SQL query to get version number from database through a batchfile.</p>
  
  <pre><code>sqlcmd.exe -S localhost -d MyDB 
             -Q "set nocount on;Declare @VersionNumber nvarchar(128) set @VersionNumber = (select top 1 versionnumbe from Table_schemaversion order by Id desc)  print 'Your Previous Version is: ' + @VersionNumber "
  </code></pre>
  
  <p>This query is working fine, and producing the correct result. </p>
  
  <p>But now I need to store this result into a local variable of the batch file. And I cannot use any external file here, I have to do this by the query written above, only.</p>
  
  <p>How can I do this? Can anybody let me me about a solution to do this? </p>
  
  <p>Thanks in advance.....</p>