One of our tables has very very long records in a particular column. These queries are used infrequently, but are necessary.
I have been using sqlcmd utility in bash like so:
-- getfile.sql
SET NOCOUNT ON;
-- Disable message for next USE command
:setvar SQLCMDERRORLEVEL 1
USE myDb;
SELECT myField
FROM myTable
GO
-- Reenable
:setvar SQLCMDERRORLEVEL 0
# getfile.sh
sqlcmd \
-S $server \
-U $username \
-P $password \
-y 0 \
-I getfile.sql > filename.txt
-y 0
being the trick here that allows me to get my text without it being truncated.
So now I need to convert this to PowerShell.
Invoke-Sqlcmd `
-ServerInstance $server `
-Username $username `
-Password $password `
-InputFile 'get_clientfile.sql' `
-Variable $StringArray `
| Out-File 'filename.txt'
But sadly my output is limited to:
myField
-----------------
BEGIN…
I also tried using MaxCharLength
and MaxBinaryLength
to no avail.
So far I have not discovered a way to prevent it from truncating output.
Also notice it is not respecting my sqlcmd commands like :setvar
. One way around this, what -y
really does (I think) might be to set the SQLCMDMAXVARTYPEWIDTH
to 0. But I can't find a way to set variables like this when using Invoke-SqlCmd
.
Any help much appreciated!