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

%結果%設置爲實際結果的前256個字符。SQLCMD僅返回列的前256個字符

有沒有一種方法可以得到查詢的整個輸出?

回答

1

默認情況下,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不得不被刪除。