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
ECHO 1 >C:\Pharmsuite\Vercheck.txt
Or in your case:
SET @CMD = 'ECHO '+@Ver+' >'+@Vercheck
It also works with this command (making sure there is a space before
ECHO [thanks to Andriy M]):
SET @CMD = '>'+@Vercheck+' ECHO '+@Ver
You should look at:
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.