You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

如何用bcp命令带参数调用Azure SQL存储过程并导出CSV

解决Azure SQL中用bcp通过AAD认证执行带参数存储过程并导出结果的问题

你之前的命令失败核心原因有两个:

  • 导出查询/存储过程结果需用queryout参数,而非out(out仅适用于直接导出表或视图)
  • 调用存储过程必须用EXEC语句包裹,不能直接写存储过程名加参数

以下是修正后的可行命令:

1. CMD环境下的命令

bcp "EXEC DatabaseName.dbo.MyStoreProcedure 'Parameter1','Parameter2'" queryout V:\MyDocuments\SourceType.csv -U viratkohli@conco.com -S Servername.database.windows.net -G -c -t","

2. PowerShell环境下的命令

$SqlQuery = "EXEC DatabaseName.dbo.MyStoreProcedure 'Parameter1','Parameter2'"
bcp $SqlQuery queryout V:\MyDocuments\SourceType.csv -U viratkohli@conco.com -S Servername.database.windows.net -G -c -t","

额外注意事项

  • 如果参数是数值类型,去掉参数两侧的单引号即可
  • 若参数包含单引号等特殊字符,需在SQL语句中用两个单引号转义,例如参数值为O'Neil时,需写成'O''Neil'
  • 确保你的AAD账号拥有目标存储过程的执行权限,以及对存储过程返回结果集的读取权限

内容的提问来源于stack exchange,提问作者Vinny

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.07.07 10:16:23