Search code examples
windowsbatch-filecmdsqlcmd

SQLCMD returns only the first 256 characters of column


FOR /f "delims=" %%a IN ('"%SQLCMD%" -E -S %Server% -d %DestDb% -h-1 -i GetResult.sql') do (
  SET Result=%%a
)
ECHO "%Result%"

%Result% is set to the first 256 characters of the actual result.

Is there a way I can get the entire output of the query?


Solution

  • SQLCMD limits variable length columns to 256 by default. The -y 0 parameter fixed this.

    FOR /f "delims=" %%a IN ('"%SQLCMD%" -E -S %Server% -d %DestDb% -y 0 -i GetResult.sql') do (
      SET Result=%%a
    )
    ECHO "%Result%"
    

    -h and -y parameters are mutually exclusive, so -h-1 had to be removed.