Still celebrating National IT Professionals Day with 3 months of free Premium Membership. Use Code ITDAY17

x
?
Solved

SSIS. Execute SQL Task Parameter Mapping

Posted on 2014-10-23
3
Medium Priority
?
375 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 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 2000 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 Backup Tool for VMware and Hyper-V

Restore full virtual machine or individual guest files from 19 common file systems directly from the backup file. Schedule VM backups with PowerShell scripts. Set desired time, lean back and let the script to notify you via email upon completion.  

Question has a verified solution.

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

Use this article to create a batch file to backup a Microsoft SQL Server database to a Windows folder.  The folder can be on the local hard drive or on a network share.  This batch file will query the SQL server to get the current date & time and wi…
I have a large data set and a SSIS package. How can I load this file in multi threading?
Add bar graphs to Access queries using Unicode block characters. Graphs appear on every record in the color you want. Give life to numbers. Hopes this gives you ideas on visualizing your data in new ways ~ Create a calculated field in a query: …
In this video you will find out how to export Office 365 mailboxes using the built in eDiscovery tool. Bear in mind that although this method might be useful in some cases, using PST files as Office 365 backup is troublesome in a long run (more on t…

721 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