在SSIS中将参数传递给BCP命令执行SQL任务

时间:2022-04-23 16:35:40

First of all, can i pass parameters for Path in BCP command?

首先,我可以在BCP命令中传递Path的参数吗?

I wrote this query in Exec SQL task

我在Exec SQL任务中编写了这个查询

EXEC xp_cmdshell 'bcp "SELECT * FROM TLC.dbo.World_Hosts" queryout `"C:\Users\akshay.kapila\Desktop\TLC\Foreachlearn\Dest\?.txt" -T -c -t '`

I have given ? in path. I want specific countries in place of that. They are held in variable "Country".I am using Foreach loop which creates rather it should create a file ex Aus.txt,In.txt everytime loop runs for that specific value.

我给了 ?在路上。我想要特定的国家代替那个国家。它们保存在变量“Country”中。我正在使用Foreach循环,它创建了一个文件ex Aus.txt,In.txt每次循环运行该特定值。

Can i use this way. If not, how can i pass variable value to Path in BCP command?

我可以用这种方式吗?如果没有,我如何在BCP命令中将变量值传递给Path?

1 个解决方案

#1


1  

You can use variable as the SQLSourceType in your Execute SQL Task.

您可以在执行SQL任务中将变量用作SQLSourceType。

Create a variable to hold your bcp command, it may look like:

创建一个变量来保存你的bcp命令,它可能看起来像:

"EXEC xp_cmdshell 'bcp \"SELECT ''abc'' as output\" queryout \"" + @[User::strFileName] + "\" -T -c -t '"

Here @[User::strFileName] is the dynamic file you want to generate.

这里@ [User :: strFileName]是您要生成的动态文件。

Then in the Execute SQL Task, change SQLSourceType to variable, and select the variable you just generated.

然后在Execute SQL Task中,将SQLSourceType更改为variable,并选择刚刚生成的变量。

#1


1  

You can use variable as the SQLSourceType in your Execute SQL Task.

您可以在执行SQL任务中将变量用作SQLSourceType。

Create a variable to hold your bcp command, it may look like:

创建一个变量来保存你的bcp命令,它可能看起来像:

"EXEC xp_cmdshell 'bcp \"SELECT ''abc'' as output\" queryout \"" + @[User::strFileName] + "\" -T -c -t '"

Here @[User::strFileName] is the dynamic file you want to generate.

这里@ [User :: strFileName]是您要生成的动态文件。

Then in the Execute SQL Task, change SQLSourceType to variable, and select the variable you just generated.

然后在Execute SQL Task中,将SQLSourceType更改为variable,并选择刚刚生成的变量。