sql server - Error when exeuting BCP: BCP host-files must at least contain one column -
i want use bcp in database. purpose wrote query:
exec xp_cmdshell 'bcp "select rtrim(ltrim(anumber)),rtrim(ltrim(bnumber)),rtrim(ltrim(duration)) [cdrdb].[dbo].[cdrtable]" queryout d:\myout.txt -s . -ucdrlogin -pbeh1368421 -f "d:\myformat.fmt" '
the format file myformat.fmt
detail this:
9.0 3 1 sqlnchar 0 5 "," 1 anumber "" 2 sqlnchar 0 10 "," 2 bnumber "" 3 sqlnchar 0 10 "\r\n" 3 duration ""
when run bcp command error:
how can solve problem?
you have -s .
switch. don't think that's enough sql server. execute following in ssms:
select @@servername;
and use output of query instead of .
.
second, there need format file? supply following switches instead: -w -t, -r\r\n
declare @stmt varchar(8000)='bcp "select rtrim(ltrim(anumber)),rtrim(ltrim(bnumber)),rtrim(ltrim(duration)) [cdrdb].[dbo].[cdrtable]" queryout "d:\myout.txt" -ucdrlogin -pbeh1368421 -w -t, -r\r\n -s ' + @@servername; exec master.sys.xp_cmdshell @stmt;
Comments
Post a Comment