Solved

SSIS. Execute SQL Task Parameter Mapping

Posted on 2014-10-23
3
282 Views
Last Modified: 2016-02-11
Hi there,

I have this SQL query in the SQL Execute Task Editor:

INSERT INTO [aging].[dbo].[ag_ageddebtor]
SELECT * FROM [aging].[dbo].[ag_ageddebtor_staging]
WHERE [Co Code] IN (?)

Open in new window

.

In the parameter mapping I have the following user defined variable: 'User::CompanyCode' that has the following values ('8560',4956','5863','6245') and it is a string data type.

I have set the parameter mapping as follows for this variable:
1. Direction: Input
2. Data Type: VARCHAR
3. Parameter Name: 0
4. Parameter Size: -1

The SQL does not execute as expected i.e. returns 0 records.

However, if I put query in the SQL Execute task it works:

INSERT INTO [aging].[dbo].[ag_ageddebtor]
SELECT * FROM [aging].[dbo].[ag_ageddebtor_staging]
WHERE [Co Code] IN ('8560',4956','5863','6245')

Open in new window

.

What I'm I doing wrong?

Thanks

OS
0
Comment
Question by:onesegun
  • 2
3 Comments
 
LVL 24

Expert Comment

by:Phillip Burton
ID: 40399852
You said:

In the parameter mapping I have the following user defined variable: 'User::CompanyCode' that has the following values ('8560',4956','5863','6245') and it is a string data type.

Does User::CompanyCode have ('8560',4956','5863','6245') or '8560',4956','5863','6245' - i.e. are the brackets included?
0
 

Author Comment

by:onesegun
ID: 40399882
No the brackets are not included.....
0
 
LVL 24

Accepted Solution

by:
Phillip Burton earned 500 total points
ID: 40399905
I think it's because SSIS is including an extra pair of quotes.

For example, you had

SELECT * FROM Production.Product WHERE ProductName like ?

and you had a parameter of Hello, then it would translate it as:

SELECT * FROM Production.Product WHERE ProductName like 'Hello'

Note that the above has gain extra quote marks.

Therefore, I imagine that SSIS is adding an extra pair of quotation marks around the entire parameter. I don't think the following code would work, yet that is what is being created:

INSERT INTO [aging].[dbo].[ag_ageddebtor]
SELECT * FROM [aging].[dbo].[ag_ageddebtor_staging]
WHERE [Co Code] IN ('''8560'',''4956'',''5863'',''6245''')

Open in new window


My suggestion, therefore, is to have the entirety of the SQL code passed as a parameter, i.e. create the entire SQL string yourself, and use that in the Execute SQL. Then there would be no problems.
0

Featured Post

Free Tool: Site Down Detector

Helpful to verify reports of your own downtime, or to double check a downed website you are trying to access.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

SQL Server engine let you use a Windows account or a SQL Server account to connect to a SQL Server instance. This can be configured immediatly during the SQL Server installation or after in the Server Authentication section in the Server properties …
Occasionally there is a need to clean table columns, especially if you have inherited legacy data. There are obviously many ways to accomplish that, including elaborate UPDATE queries with anywhere from one to numerous REPLACE functions (even within…
Two types of users will appreciate AOMEI Backupper Pro: 1 - Those with PCIe drives (and haven't found cloning software that works on them). 2 - Those who want a fast clone of their boot drive (no re-boots needed) and it can clone your drive wh…

839 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question