问题描述
我正在使用bcp工具通过以下命令将数据从SQL复制到文本文件:
I'm copying data from SQL to text file using bcp tool with following command:
bcp.exe "exec <StoredProcedure>" queryout "temp.txt" -T -r\n -c
此命令将在测试环境中按预期运行,并创建/更新所需的文件,而不会出现其他提示.
This command runs as expected on test environment and creates/updates required file without additional prompts.
但是,当它在客户端环境中运行时,bcp还会提示输入字段长度,前缀和字段终止符-因此,当从SQL Agent作业运行命令时,它将陷入无限等待状态.
But when it's run in client's environment, bcp additionally prompts for field length, prefix and field terminator- so when command is run from SQL Agent job, it get's stuck in infinite wait.
任何想法为什么会发生这种情况?
Any ideas why is this happening?
基于 bcp文档 ,使用-c参数时-不应提示输入类型等,并且应使用char作为存储类型,不带前缀,并使用\ t作为字段终止符.
Based on bcp documentation, when -c parameter is used - it shouldn't prompt for type, etc. and should use char as the storage type, with no prefix, and \t as field terminator.
推荐答案
我猜您的测试环境和客户端环境实际执行命令之间的某个位置,该命令将"/n"变成一条真正的换行符.尝试将"-c"放在"-r"之前,看看会发生什么.
I would guess the somewhere between your test environment and the client's environment's actual execution of the command that the "/n" is getting turned into a real new-line. Try putting the "-c" before the "-r" and see what happens.
这篇关于使用BCP将数据写入文本文件提示输入文件存储类型的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!