Sqlcmd - How to get around column length restriction without empty spaces?

I am trying to use sqlcmd on a windows machine with SQL Server 2005 to write a query to a csv file. Usually we use command line options:

-l 60 -t 300 -r 1 -b -W -h -1 

However, columns are truncated with 256 bytes. In an attempt to get around this, I tried using this command line option instead of -W:

 -y 8000 

This captures all the fields, but the problem with this method is that the file takes off from just over 1 mb to 200 mb due to all the extra space (I understand that 8000 is probably too large, but it will probably be smaller 4000, and now I only work with a small subset of data). The -W option usually excludes all this extra space, but when I try to use them together, it tells me that they are mutually exclusive.

Is there a way to get sqlcmd in this limit, or does anyone know if another program (like bcp or osql) will make it easier?


Edit: Here are the code snippets that we use to get a truncated field (similar code is used for a group of fields):

 SELECT ALIASES.AliasList as complianceAliases, 

...

 LEFT OUTER JOIN (Select M1.ID, M1.LIST_ID,stuff((SELECT '{|}' + isnull(Content2,'')+' '+isnull(Content3,'')+' '+isnull(Content4,'')+' '+isnull(Content5,'')+' '+isnull(Content6,'')+' '+isnull(Content7,'') FROM fs_HOST3_TEST_web.ISI_APP_COMP_MULTI M2 with (nolock) WHERE M1.LIST_ID = M2.LIST_ID and M1.ID = M2.ID and M1.TYPE = M2.TYPE FOR XML PATH('') ),1,1,'') as AliasList FROM fs_HOST3_TEST_web.ISI_APP_COMP_MULTI M1 with (nolock) WHERE M1.LIST_ID = 2001 AND M1.TYPE = 'Aliases' GROUP BY m1.list_id,m1.ID,m1.Type) as ALIASES ON ALIASES.LIST_ID = PAIR.COMP_LIST_ID AND ALIASES.ID = PAIR.COMP_ID 
+7
source share
1 answer

I decided to solve this using the -y0 argument. It still left a bunch of spaces, but it looks like it only reached the end of the longest piece of data in each field.

Then I ran the output through a program that removed duplicate spaces and solved all problems.

+12
source

All Articles