How to set a sqlcmd output to a batch variable?

前端 未结 1 1882
醉话见心
醉话见心 2021-01-02 19:15

I\'m trying to set the output of a sqlcmd query to a variable in a batch file.

Here\'s my query:

sqlcmd -S  -d  -Q \"         


        
相关标签:
1条回答
  • 2021-01-02 19:41

    Try turning on NOCOUNT:

    for /f %%a in ('sqlcmd -S <SERVER> -d <DATABASE> -Q "SET NOCOUNT ON; select max(Column1)+1 from Table1"') do set ColumnVar=%%a
    echo %ColumnVar%
    pause
    
    0 讨论(0)
提交回复
热议问题