我想知道如何在我的bcp中使用存储过程合并参数,错误在第8行@JDEBatchNumber 任何想法如何添加此参数? 谢谢
DECLARE @cmd varchar(500)
Declare @TimeStamp as nvarchar(100) = Replace((CONVERT(varchar(25), getdate(), 121)),':','')
Declare @JDEBatchNumber as float = '566521'
Declare @NumberOfRecords as bigInt = (select count(*) From [JDE_PRODUCTION].[PRODDTA].[F0911] Where GLICU = @JDEBatchNumber)
if @NumberOfRecords > 0
SET @cmd = 'BCP "EXECUTE [F0902].[D365O].[Get-F0911NewRecordsByBatchNumber] '+@JDEBatchNumber+'" QUERYOUT "D:\D365O\DataSource\F0911\Input\'+@TimeStamp+'.csv" -c -t\^, -T -S' + @@SERVERNAME + ''
EXECUTE MASTER..xp_cmdshell @cmd;
答案 0 :(得分:0)
你不能用一个+来连接一个浮点数,因为它试图添加它......只是先把它抛出来。
SET @cmd = 'BCP "EXECUTE [F0902].[D365O].[Get-F0911NewRecordsByBatchNumber] '+ cast(@JDEBatchNumber as varchar(64))+'" QUERYOUT "D:\D365O\DataSource\F0911\Input\'+@TimeStamp+'.csv" -c -t\^, -T -S' + @@SERVERNAME + ''
虽然,我认为这更像你想要的......
SET @cmd = 'BCP "EXECUTE [F0902].[D365O].[Get-F0911NewRecordsByBatchNumber] '''+ cast(@JDEBatchNumber as varchar(64))+''' QUERYOUT "D:\D365O\DataSource\F0911\Input\'+@TimeStamp+'.csv" -c -t\^, -T -S' + @@SERVERNAME + ''