开发者

8192 limitation on text column while exporting to file?

I have looked at this question which is essentially the same but the OP accepted 'using other tools' as an answer. Basically, I am trying to export data from a table to a delimited file but because of the 8192 character limit, the output text is getting truncated. I could not find any good approaches that work (for me at least).

If SSMS and sqlcmd (not sure if the limitation applies to this as well. 开发者_运维问答I am trying at the moment) are my only options, is there a way to workaround this limitation and dump text columns of higher widths?


Have you considered using a simple PowerShell script or a command-line app using C#? If it can SELECT all of the data then it should certainly be able to write it all to a file.

EDIT 2011-08-03

I was unable to get this working with PowerShell or sqlcmd. The former seems to truncate output at 4000 characters and the latter at 256. However my good old friend VBScript once again proved that new and shiny is not always the best... the code is much more tedious to write, but it works. Save as .vbs file, make the appropriate changes to lines 2, 3 and 6 (and 9 if you want more columns, transformation of the data, different delimiters, etc).

set conn = createobject("ADODB.Connection")
conn.open "provider=SQLOLEDB.1;data source=.;user id=user;password=pass;"
set rs = conn.execute("SELECT VarcharMaxCol FROM dbo.TableName")

set fso = createobject("Scripting.FileSystemObject")
set f = fso.CreateTextFile("c:\path\from_vbs.csv", true)

do while not rs.eof
    f.writeline vbCrLf & rs(0)
    rs.movenext
loop

rs.close   : set rs   = nothing
conn.close : set conn = nothing
f.close    : set f    = nothing
set fso  = nothing

I will post back here if I get any answers from my PowerShell guru friends about how they deal with > 4K.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜