This article explains how to pass a variable into a source query.
1. When you first create the map, you need to hard code the field that will be the variable. The source query will not validate with a variable in the source query.
For example: SELECT * FROM RM00101
2. Create your map, and map the fields as you normally would.
3. Your code to set the variable should be in a pre map task. A very simple example of this would be: GlobalMessage = “RM00101”
4. After the map is created and running correctly, replace your hard coded value with your variable.
For example: SELECT * FROM GlobalMessage
5. Then run the map. The map will run (but not validate or be able to adjust mappings since global variables do not have values until runtime). If you need to edit the mappings you need to hard code your source query again before you can adjust the mappings in the mapping windows.
If the global variable is being used in the WHERE clause statement and contains a string value then the quotes would need to be put around the value that is assigned in the pre-map task.
1. Build a map with your query to get the column names:
SELECT * FROM RM00101 WHERE CUSTNMBR = ‘AARONFIT0001’
2. Create your map, and map the fields as you normally would.
3. Your code to set the variable should be in a pre map task. A very simple example of this would be: GlobalMessage = “‘AARONFIT0001′”
4. Place the global variable in the source query
SELECT * FROM RM00101 WHERE CUSTNMBR = GlobalMessage
NOTE: Notice that in the last example there are single quotes inside the double quotes. This is because SQL requires strings to be surrounded by single quotes.