This is not an answer to your question, but a simplification. A view on the table that provides the complete bcp statement would avoid a lot of parameters. (Can @@Servername be the instance?) Then SSIS can query the view and run each command.
Edit: added a bcp to add column names to the file
SELECT
'bcp "SELECT name from sys.columns WHERE object_id = OBJECT_ID('''
+ SUBSTRING(@SqlCommand, CHARINDEX(' FROM', @SqlCommand) + 6, 8000) + ''')'
+ '" queryout " + FileLocation + '\' + FileName + '" '
+ '-S"' + @@SERVERNAME + '" -d"' + DatabaseName + '" -t, -c -T'
as [BcpCmdColumnNames],
'bcp "' + SqlCommand + '" queryout " + FileLocation + '\' + FileName + '" '
+ '-S"' + @@SERVERNAME + '" -d"' + DatabaseName + '" -t, -c -T'
as [BcpCmdTableData]
FROM dbo.Falina_Config
I might also avoid SSIS and use a Job Step running PowerShell.exe. Here is a possible PowerShell script using DBATools. (You can use any alternate to do the query without DBATools.)
https://www.mssqltips.com/sqlservertip/6172/execute-powershell-script-from-ssis-package/
https://dbatools.io/
Edit: Added query for column names
param(
[string] $instance = 'myinstance',
[string] $dbname = 'mydatabase'
)
$queryExtracts = 'select DatabaseName, SqlCommand, FileLocation, FileName from dbo.Falina_Config'
$extracts = Invoke-DbaQuery -SqlInstance $instance -Database $dbname -Query $query -CommandType Text |
select DatabaseName, SqlCommand, FileLocation, FileName
foreach ($extract in $extracts) {
$fileLocation = $extract.FileLocation
$fileName = $extract.FileName
$file = Join-Path $fileLocation $fileName
$databaseName = $extract.DatabaseName
#$queryColumnNames = "select name from sys.columns where object_id = OBJECT_ID('[$($extract.TableSchema)].[$($extract.TableName)]')"
#$queryTableData = "select * from [$($extract.TableSchema)].[$($extract.TableName)]" # this might be safer
$querySqlCommand = $extract.SqlCommand
#bcp "$queryColumnNames" queryout "$fileName" -S"$instance" -d"$databaseName" --% -t, -c -T
#bcp "$queryTableData" queryout "$fileName" -S"$instance" -d"$databaseName" --% -t, -c -T
bcp "$querySqlCommand" queryout "$fileName" -S"$instance" -d"$databaseName" --% -t, -c -T
}
The --% stops PowerShell from parsing or replacing the stuff in the rest of the line. For example, it would not like the comma.
Warning, I did not test any of this so expect it to require modification. It would be amazing if I got the quoted quotes right.