SQLCMD returns 仅列的前 256 个字符

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% 设置为实际结果的前 256 个字符。

有什么方法可以获得查询的全部输出吗?

SQLCMD 默认将可变长度列限制为 256。 -y 0 参数修复了这个问题。

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

-h 和 -y 参数是互斥的,因此必须删除 -h-1。

是的,您可以使用 -y 0 --> 0- unlimited 获得完整输出,但请注意这可能会导致性能问题。

sqlcmd -e -s server_name -Q "your query" -y 0> op_file_path

注:-h-y互斥