I'm trying to set multiple variables to the result of an SQL Query that returns a single row with multiple columns. The SQL statement is in the format of:
SELECT top 1
a,
b,
c = x + y,
d
FROM tablename
WHERE aSwitch = 1
So I wish to use an 'Execute SQL Query' task which will set 4 package variables with the results of the query.
For example, if the results of the query were:
| a | b | c | d |
-------------------------------------
| duck | cow | rabbit | 42 |
Then the state of the variables after execution would be:
var1 = duck
var2 = cow
var3 = rabbit
var4 = 42
Any ideas?
(using VS/SQL 2005)
Execute SQL Task in SSIS allows user to execute parameterized SQL statement and create mapping between these parameters and the SSIS variables. To add a parameter into a SQL statement you must use a parameter marker which differs based on the connection type. Select * from table where ID > ?
Assigning multiple values to multiple variablesIf you have to populate multiple variables, instead of using separate SET statements each time consider using SELECT for populating all variables in a single statement. This can be used for populating variables directly or by selecting values from database.
In the SQL task, under General menu, set the ResultSet property to SingleRow.
Then, in the ResultSet menu, add the variables in the order of your select clause and map the aliases with the variables. For exemple :
SELECT 1 AS One, 2 AS Two
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With