title: .BAT File to Execute SQL Query (Backup)
body: <p>I have an SQL script which is as follows:-</p>
  
  <pre><code>   BACKUP DATABASE [**********] TO  DISK = N'G:\Super Sacred Databases\Orderwise Backup\20-04-2017-13-05.bak' WITH NOFORMAT, NOINIT,  NAME = N'**********-Full Database Backup', SKIP, NOREWIND, NOUNLOAD,  STATS = 10
  GO
  </code></pre>
  
  <p>On the server I wish to run a .bat file that i can schedule on windows task scheduler.</p>
  
  <p>My confusion is, how do i write a .bat file to execute this query on the SQL Server?</p>
  
  <p>I have so far tried to use this: </p>
  
  <pre><code>sqlcmd -U myLogin -P myPassword -S MyServerName -d MyDatabaseName 
      -Q ?
  </code></pre>
  
  <p>The problem is that is doesnt work at all for me, furthermore i have no idea what the -Q ? would be to run a specific query in SQL Server.</p>
  
  <p>Furthermore im not sure exactly how to specify the Servername or Databasename in the fields required.</p>
  
  <p>I know im new to this, but im trying hard.</p>
  
  <p>Thanks in advance for your help!</p>
  
  <p>CONTINUED -</p>
  
  <p>Now i am working with this </p>
  
  <pre><code>sqlcmd -U s******a -P 0****! -S LPSERVER\ORDERWISE 
  -Q "BACKUP DATABASE [********Live] TO  DISK = N'G:\Super Sacred Databases\Orderwise Backup\20-04-2017-13-05.bak' WITH NOFORMAT, NOINIT,  NAME = N'******estLive-Full Database Backup', SKIP, NOREWIND, NOUNLOAD,  STATS = 10
  GO
  "
  </code></pre>
  
  <p>But it just doesnt seem to do anything just shows the cmd line in the CMD interface and does nothing more.</p>
  
  <p>Any suggestions?</p>