2015-11-12 51 views
0

我正在使用xp_cmdshell,我希望输出到文本文件以分号分隔。我已测试以下内容:xp_cmdshell分号分隔

-- To allow advanced options to be changed. 
EXEC sp_configure 'show advanced options', 1; 
GO 
-- To update the currently configured value for advanced options. 
RECONFIGURE; 
GO 
-- To enable the feature. 
EXEC sp_configure 'xp_cmdshell', 1; -- 1 for at enable 
GO 
-- To update the currently configured value for this feature. 
RECONFIGURE; 
GO 

-- Extracting information from the database 
EXEC xp_cmdshell 'bcp "SELECT TcpIpAddress FROM [SIT-DVH].[dbo].[Preb_Idera]" queryout "C:\Output\Ip_outputSemi.txt" -T -c -t;' 


-- To allow advanced options to be changed. 
EXEC sp_configure 'show advanced options', 1; 
GO 
-- To update the currently configured value for advanced options. 
RECONFIGURE; 
GO 
-- To disable the feature. 
EXEC sp_configure 'xp_cmdshell', 0; -- 0 for at disable 
GO 
-- To update the currently configured value for this feature. 
RECONFIGURE; 
GO 

我已经看过好几个地方说过,设置-t;应使输出被分号分隔,但输出仍然是:

XXXX YYYY ZZZZ

+0

你确定你正在检查在正确的位置正确的文件?首先删除文件,只是为了确保。除了在两者之间增加一个空白区域,即'-t; ',不知道还有什么问题可以解决。 – Greg

+0

我删除了旧文件,我尝试过使用空格,并且在-t仍然是相同的结果之间没有空格。 – Santelices

+0

好吧,没有限定的原因是因为您正在选择一个列。你在repro上有什么不符合你的输出。 – Greg

回答

0

我发现了解决方案,因为作为随后的输出:

xxx 
zzz 
yyy 

我需要改变-t; to -r;因为我只有每行一个字段和[-r row_term],输出为如下:

XXX,ZZZ; YYY