Using Echo statement writes Echo is ON in the text file Following code is used for write a number in the text file but instead it is writing "Echo is ON" into the text file. 

SET @CMD = 'ECHO '+@Ver+'&gt;'+@Vercheck      
  Print @CMD

EXEC xp_cmdshell @CMD  
  ,NO_OUTPUT 


Print @CMD  gives  "ECHO 1>C:\Pharmsuite\Vercheck.txt"

Here instead of 1, the query is writing "Echo is ON".
This command: ECHO 1&gt;C:\Pharmsuite\Vercheck.txt

Does not do what you think it should do because 1> has a special meaning.

This problem can be fixed by adding a space before &gt;:

ECHO 1 &gt;C:\Pharmsuite\Vercheck.txt


Or in your case:

SET @CMD = 'ECHO '+@Ver+' &gt;'+@Vercheck


It also works with this command (making sure there is a space before ECHO [thanks to Andriy M]):

SET @CMD = '&gt;'+@Vercheck+' ECHO '+@Ver


You should look at:


Technet Using command redirection operators 
SS64 Redirection:



  Numeric handles:
  
  STDIN  = 0  Keyboard input
  STDOUT = 1  Text output
  STDERR = 2  Error text output
  UNDEFINED = 3-9  
  
  command 2> filename       Redirect any error message into a file
     command 2>> filename      Append any error message into a file
    (command)2> filename       Redirect any CMD.exe error into a file  


Anyhow, you should avoid using xp_cmdshell. If you are trying to output something, Powershell or SQL Server command line commands are better options. 

Using Powershell and Invoke-Sqlcmd:

Invoke-Sqlcmd -Query "SELECT GETDATE() AS TimeOfQuery;" -ServerInstance "MyComputer\MyInstance"
Invoke-Sqlcmd -InputFile "C:\MyFolder\TestSQLCmd.sql" | Out-File -filePath "C:\MyFolder\TestSQLCmd.rpt"


You obviously have to adapt it to your own requierements and you must also look at Daniel Hutmacher's answer using osql.