0

I'm trying to use "Execute SQL Task" in SSIS to get a value to be stored in a user variable. The documentation says to use '?' as a placeholder for parameters in the query but when I do I get a syntax error trying to parse the query. So the query is like this:

SELECT ? = AVG(Score) FROM Scorecards

I've also tried adding OUTPUT after the '?'. All examples I can find for having an output parameter are similar to

EXEC ? = MyStoredProc param1, param2, ...

This isn't of any use though since I'm not using a stored proc. The use of the parameter seems similar though so why won't SSIS take it for a select statement?

2
  • I can't find an example in my code, but I'm sure you also have to use the Parameter Mapping and/or Result Set to get the data to the user variable. Commented Mar 25, 2011 at 22:02
  • Yes, I've also added to Parameter Mapping though SSIS isn't getting that far. It gives me a syntax error when I press "Parse Query" to check if it think the statement is correct. Commented Mar 25, 2011 at 22:09

1 Answer 1

2

You'll need to set the ResultSet property to Single Row, then amend your query to something like:

select avg(score) as AvgScore from ScoreCards

Then in the Result Set pane, click Add, set the Result Name to AvgScore, and your variable to Variable Name (for example, User::AvgScore).

Sign up to request clarification or add additional context in comments.

3 Comments

I tried this. While it does execute successfully the variable is not updated in the variables window when it hits a breakpoint after the task.
The variable value doesn't update in that window. You'll be able to to check the value if you add a watch on the variable and open the Watch or Locals window during execution.
I was using an ODBC driver and found using the number 1 as the Result Name worked instead of entering the column alias. Just in case that helps anyone out there :)

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.