Это заявление BCP добавляет пробел между моими данными. См. Изображение BCP добавляет пробел в выходной файл
Это DDL и данные образца - что мне нужно изменить, чтобы пространство не было добавлено? (Пустая колонна)
Declare @TestMe Table
(
field1 varchar(20),
field2 varchar(20),
field3 varchar(20),
field4 varchar(20),
field5 varchar(20),
field6 varchar(20),
field7 varchar(20),
field8 varchar(20),
field9 varchar(20),
field10 varchar(20),
field11 varchar(20),
field12 varchar(20),
field13 varchar(20),
field14 varchar(20),
field15 varchar(20),
field16 varchar(20),
field17 varchar(20)
)
Insert Into @TestMe Values
('Blue', 'Red', NULL, NULL, NULL, NULL, 'Seven', 'Eight', NULL, NULL, Null, Null, 'Pink', 'Orange', 'NFL', 'Size', 'Last')
Declare @field1 varchar(20),@sql nvarchar(4000), @filename varchar(100)
Set @field1 = 'Blue'
Set @filename = 'C:\Test.csv'
Set @sql = 'bcp "SELECT ''one'',''two'',''three'',''four'',''five'',''six'',''seven'',''eight'',''nine'',''ten'',''eleven'',''twelve'',''thirteen'',''fourteen'',''fifteen'',''sixteen'',''seventeen'' UNION ALL SELECT CHAR(34)+CONVERT(varchar(10),[field1],101)+CHAR(34),CHAR(34)+CAST([field2] As VARCHAR(MAX))+CHAR(34),CHAR(34)+CAST([field3] As VARCHAR(MAX))+CHAR(34),CHAR(34)+CAST([field4] As VARCHAR(MAX))+CHAR(34),CHAR(34)+CAST([field5] As VARCHAR(MAX))+CHAR(34),CHAR(34)+CAST([field6] As VARCHAR(MAX))+CHAR(34),CHAR(34)+CAST([field7] As VARCHAR(MAX))+CHAR(34),CHAR(34)+CAST([field8] As VARCHAR(MAX))+CHAR(34),CHAR(34)+CAST([field9] As VARCHAR(MAX))+CHAR(34),CHAR(34) + CAST([field10] As VARCHAR(MAX))+CHAR(34),CHAR(34) + CAST([field11] As VARCHAR(MAX))+CHAR(34),CHAR(34) + CAST([field12] As VARCHAR(MAX))+CHAR(34),CHAR(34)+CAST([field13] As VARCHAR(MAX))+CHAR(34),CHAR(34)+CAST([field14] As VARCHAR(MAX))+CHAR(34),CHAR(34)+CAST([field15] As VARCHAR(MAX))+CHAR(34),CHAR(34)+CAST([inventorycode] As VARCHAR(MAX))+CHAR(34),CHAR(34)+CAST([field16] As VARCHAR(MAX))+CHAR(34) FROM [@TestMe] WHERE field1 = '''[email protected]+'''" queryout "'
SET @sql = @sql + @filename + '" -c -t, -T -S '[email protected]@SERVERNAME
exec master..xp_cmdshell @sql