带参数运行 proc 时 BCP 函数序列错误
我一直在尝试创建一个存储过程,该存储过程使用动态 SQL 来组装 bcp 命令,以将数据从参数化存储过程导出到 csv 文件。
最初遇到主机数据文件访问问题,我认为是文件系统权限。
现在,当我运行过程时,我一直收到填充错误:
SQLState = S1010,NativeError = 0 Error = [Microsoft][SQL Server Native Client 10.0]函数序列错误
过程代码如下:
ALTER PROCEDURE [dbo].[sp_MakeMarketingListExports]
@includeInService varchar(1) = NULL,
@includeMLM varchar(1) = NULL,
@includeQuoteNoodle varchar(1) = NULL,
@netective varchar(1) = NULL,
@cyberChex varchar(1) = NULL,
@agentsAdvantage varchar(1) = NULL,
@quoteNoodle varchar(1) = NULL,
@mlmListSubscriber varchar(1) = NULL,
@state varchar(10) = NULL,
@mailerID varchar(10) = NULL,
@filePath varchar(250)
AS
BEGIN
-- SET NOCOUNT ON added to prevent extra result sets from
-- interfering with SELECT statements.
SET NOCOUNT ON;
DECLARE @command varchar(500);
SET @command = 'bcp "exec InternalML..sp_SelectMarketingListMembers '
+ '@includeInService = ' + COALESCE(@includeInService, 'NULL') + ', '
+ '@includeMLM = ' + COALESCE(@includeMLM, 'NULL') + ', '
+ '@includeQuoteNoodle = ' + COALESCE(@includeQuoteNoodle, 'NULL') + ', '
+ '@netective = ' + COALESCE(@netective, 'NULL') + ', '
+ '@cyberChex = ' + COALESCE(@cyberChex, 'NULL') + ', '
+ '@agentsAdvantage = ' + COALESCE(@agentsAdvantage, 'NULL') + ', '
+ '@quoteNoodle = ' + COALESCE(@quoteNoodle, 'NULL') + ', '
+ '@mlmListSubscriber = ' + COALESCE(@mlmListSubscriber, 'NULL') + ', '
+ '@state = ' + COALESCE(@state, 'NULL') + '"'
+ ' queryout ' + COALESCE(@filePath, 'NULL')
+ ' -c -T -S ' + @@servername
SELECT @command;
EXEC xp_cmdshell @command;
END
我使用 SELECT @command 获取汇编命令进行分析。
已包含调用过程的参数名称,因此命令如下:
bcp "exec InternalML..sp_SelectMarketingListMembers @includeInService = NULL, @includeMLM = NULL, @includeQuoteNoodle = NULL, @netective = NULL, @cyberChex = NULL, @agentsAdvantage = NULL, @quoteNoodle = NULL, @mlmListSubscriber = NULL, @state = NULL" queryout C:\temp\test.csv -c -T -S SPKD18
也没有使用参数名称相同的函数序列错误消息:
bcp "exec InternalML.dbo.sp_SelectMarketingListMembers NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, @state = NULL" queryout "C:\\temp\test.csv “ -c -T -S SPKD18
关于为什么这不起作用的任何见解?顺便说一句,我已经通过 proc 运行 bcp 并将其复制到命令提示符,结果相同。问题是我在互联网上找不到太多关于此错误的信息,可能是因为它太通用了。
我可以直接在 SSMS 查询窗口中使用参数成功运行 InternalML.dbo.sp_SelectMarketingListMembers 过程,因此我非常确定它与 bcp 有关。
感谢您的帮助
I have been trying to create a stored procedure that uses dynamic SQL to assemble a bcp command to export data from a parameterized stored procedure to a csv file.
Was originally getting the host data file access issue that I think was filesystem permissions.
Now I consistantly get the fillowing error when I run the proc:
SQLState = S1010, NativeError = 0
Error = [Microsoft][SQL Server Native Client 10.0]Function sequence error
The proc code is as follows:
ALTER PROCEDURE [dbo].[sp_MakeMarketingListExports]
@includeInService varchar(1) = NULL,
@includeMLM varchar(1) = NULL,
@includeQuoteNoodle varchar(1) = NULL,
@netective varchar(1) = NULL,
@cyberChex varchar(1) = NULL,
@agentsAdvantage varchar(1) = NULL,
@quoteNoodle varchar(1) = NULL,
@mlmListSubscriber varchar(1) = NULL,
@state varchar(10) = NULL,
@mailerID varchar(10) = NULL,
@filePath varchar(250)
AS
BEGIN
-- SET NOCOUNT ON added to prevent extra result sets from
-- interfering with SELECT statements.
SET NOCOUNT ON;
DECLARE @command varchar(500);
SET @command = 'bcp "exec InternalML..sp_SelectMarketingListMembers '
+ '@includeInService = ' + COALESCE(@includeInService, 'NULL') + ', '
+ '@includeMLM = ' + COALESCE(@includeMLM, 'NULL') + ', '
+ '@includeQuoteNoodle = ' + COALESCE(@includeQuoteNoodle, 'NULL') + ', '
+ '@netective = ' + COALESCE(@netective, 'NULL') + ', '
+ '@cyberChex = ' + COALESCE(@cyberChex, 'NULL') + ', '
+ '@agentsAdvantage = ' + COALESCE(@agentsAdvantage, 'NULL') + ', '
+ '@quoteNoodle = ' + COALESCE(@quoteNoodle, 'NULL') + ', '
+ '@mlmListSubscriber = ' + COALESCE(@mlmListSubscriber, 'NULL') + ', '
+ '@state = ' + COALESCE(@state, 'NULL') + '"'
+ ' queryout ' + COALESCE(@filePath, 'NULL')
+ ' -c -T -S ' + @@servername
SELECT @command;
EXEC xp_cmdshell @command;
END
I use the SELECT @command to get the assembled command for analysis.
Have had the parameter names for the calle proc included so the command came out like:
bcp "exec InternalML..sp_SelectMarketingListMembers @includeInService = NULL, @includeMLM = NULL, @includeQuoteNoodle = NULL, @netective = NULL, @cyberChex = NULL, @agentsAdvantage = NULL, @quoteNoodle = NULL, @mlmListSubscriber = NULL, @state = NULL" queryout C:\temp\test.csv -c -T -S SPKD18
Also did it without the parameter names with the same Function sequenc error message:
bcp "exec InternalML.dbo.sp_SelectMarketingListMembers NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, @state = NULL" queryout "C:\\temp\test.csv" -c -T -S SPKD18
Any insight on why this is not working? BTW, I have run the bcp via the proc and copied it to a command prompt with the same results. The problem is that I can't find much on the internet about this error, probably because it is so generic.
I can successfully run the InternalML.dbo.sp_SelectMarketingListMembers proc with the parameters directly in SSMS Query window so am pretty sure it has to do with bcp.
Thanks for the help
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
BCP 将执行以下命令来解析结果集的格式。你能告诉我们结果吗:
BCP will execute the following to resolve the format of the resultset. Can you tell us result of this:
正如 Nathan Skerl 所描述的,bcp 将设置
fmtonly
选项并运行查询,以便在实际运行查询以生成输出之前构建输出架构。我遇到过一些副作用:#table< /code>) 实际上并未创建,因此在查询中引用时将导致
fmtonly
运行失败。As described by Nathan Skerl, bcp will set the
fmtonly
option and run the query in order to construct a schema for the output before actually running the query to generate output. There are a few side effects to this that I have encountered:#table
) are not actually created and so when referenced in the query will cause thefmtonly
-ed run to fail.