Click here to monitor SSC
SQLServerCentral is supported by Redgate
 
Log in  ::  Register  ::  Not logged in
 
 
 


Foreach and Variables...


Foreach and Variables...

Author
Message
tfalkenhagen
tfalkenhagen
Forum Newbie
Forum Newbie (4 reputation)Forum Newbie (4 reputation)Forum Newbie (4 reputation)Forum Newbie (4 reputation)Forum Newbie (4 reputation)Forum Newbie (4 reputation)Forum Newbie (4 reputation)Forum Newbie (4 reputation)

Group: General Forum Members
Points: 4 Visits: 19
Please forgive me if this is stupid but I've search everywhere and can't seem to find anything on this.

Object of SSIS: I need to go through a collection (from one select statement) and query off of that in order to set a value. For example...given results from query named "A". I then take "A" and for each record, set a column on the table to yes where certain conditions are met.

I have a fairly simple SSIS package. There is an "Execute SQL Task" that feeds a "Foreach Loop Container" that has another "Execute SQL Task" inside of it.

Feeder SQL Task
Query
SELECT isnull(MonitorAlert,'No'), WEBfeWBPhaseID
FROM tbl_WRPhase
WHERE (DATEDIFF(day, GETDATE(), ManualAlertDate) > 7) OR
(ManualAlertDate IS NULL)

ResultSet: Full result set

On the Result Set tab:
Result Name: 0
Variable Name: User:: PhasesToCheck of type Object

Foreach Loop Container
Collection Tab
Enumerator: Foreach ADO Enumerator
ADO object source variable: User:: PhasesToCheck
Rows in the first table checked

Variable Mappings Tab
Variable: User::MonitorAlert
Index: 0
Variable: User::WEBfeWBPhaseID
Index: 1


Inner SQL Task
In a query within this, how do I reference the User::WEBfeWBPhaseID variable? I've tried [User::WEBfeWBPhaseID] and @WEBfeWBPhaseID but both don't seem to work. Do I need to set the parameter mappings? I'm so confused if I've even done it right.


Thank you for any and all help. I hope I've explained it well enough. (Also, if there's a better way of doing it, please dont hesitate to say so)
Mukti
Mukti
SSC Veteran
SSC Veteran (226 reputation)SSC Veteran (226 reputation)SSC Veteran (226 reputation)SSC Veteran (226 reputation)SSC Veteran (226 reputation)SSC Veteran (226 reputation)SSC Veteran (226 reputation)SSC Veteran (226 reputation)

Group: General Forum Members
Points: 226 Visits: 747
Yes you need to set the parameters for the Execute SQL Task and use select the variables as Input types. Not sure what type of query you are using but if you are trying to execute a procedure use something like

Exec my_sp ?,? (for OLDBD type connection)

And depending on your connection type you need to set the parameter marker, parameter name etc. The following link might be useful for this
http://www.sqljunkies.com/WebLog/knight_reign/archive/2005/10/05/17016.aspx
tfalkenhagen
tfalkenhagen
Forum Newbie
Forum Newbie (4 reputation)Forum Newbie (4 reputation)Forum Newbie (4 reputation)Forum Newbie (4 reputation)Forum Newbie (4 reputation)Forum Newbie (4 reputation)Forum Newbie (4 reputation)Forum Newbie (4 reputation)

Group: General Forum Members
Points: 4 Visits: 19
Thanks. I went ahead and in the Parameter mapping section of the interior SQL Task and set this...

Variable Name: User::WEBfeWBPhaseID
Direction: Input
Data Type: LARGE_INTEGER
Parameter Name: 0

Then in the task, I use ? where I need the variable. Here's my question. Can I use it more than once?

When I run the SSIS, I get this error...

failed with the following error: "Syntax error, permission violation, or other nonspecific error". Possible failure reasons: Problems with the query, "ResultSet" property not set correctly, parameters not set correctly, or connection not established correctly.
tfalkenhagen
tfalkenhagen
Forum Newbie
Forum Newbie (4 reputation)Forum Newbie (4 reputation)Forum Newbie (4 reputation)Forum Newbie (4 reputation)Forum Newbie (4 reputation)Forum Newbie (4 reputation)Forum Newbie (4 reputation)Forum Newbie (4 reputation)

Group: General Forum Members
Points: 4 Visits: 19
Sorry, forgot to add that I tried adding this...

DECLARE @WEBfeWBPhaseID as int
SET @WEBfeWBPhaseID = ?

and then just using @WEBfeWBPhaseID when I need it but I get the same error.
Mukti
Mukti
SSC Veteran
SSC Veteran (226 reputation)SSC Veteran (226 reputation)SSC Veteran (226 reputation)SSC Veteran (226 reputation)SSC Veteran (226 reputation)SSC Veteran (226 reputation)SSC Veteran (226 reputation)SSC Veteran (226 reputation)

Group: General Forum Members
Points: 226 Visits: 747
What is the datatype of your SSIS variable? If its Int32 try to use LONG as datatype in Parameter mappings.
tfalkenhagen
tfalkenhagen
Forum Newbie
Forum Newbie (4 reputation)Forum Newbie (4 reputation)Forum Newbie (4 reputation)Forum Newbie (4 reputation)Forum Newbie (4 reputation)Forum Newbie (4 reputation)Forum Newbie (4 reputation)Forum Newbie (4 reputation)

Group: General Forum Members
Points: 4 Visits: 19
You are correct. User::WEBfeWBPhaseID is Int32. I changed the parameter mapping to be LONG but the same error comes up.

The query I've been trying (extremely simple for now) is this:

DECLARE @WEBfeWBPhaseID as int
SET @WEBfeWBPhaseID = ?

UPDATE tbl_WRPhase
SET MonitorAlert = 'Yes'
WHERE WEBfeWBPhaseID = @WEBfeWBPhaseID

Once I get it working, the query will be more complicated.
Mukti
Mukti
SSC Veteran
SSC Veteran (226 reputation)SSC Veteran (226 reputation)SSC Veteran (226 reputation)SSC Veteran (226 reputation)SSC Veteran (226 reputation)SSC Veteran (226 reputation)SSC Veteran (226 reputation)SSC Veteran (226 reputation)

Group: General Forum Members
Points: 226 Visits: 747
I did a simple test and the same scenario works absolutely fine for me. Not sure anymore what the problem could be.

The only other thing that comes to my mind is Null values, is it possible that the this parameter could be Null by any chance? NULL values can cause such errors too.
Go


Permissions

You can't post new topics.
You can't post topic replies.
You can't post new polls.
You can't post replies to polls.
You can't edit your own topics.
You can't delete your own topics.
You can't edit other topics.
You can't delete other topics.
You can't edit your own posts.
You can't edit other posts.
You can't delete your own posts.
You can't delete other posts.
You can't post events.
You can't edit your own events.
You can't edit other events.
You can't delete your own events.
You can't delete other events.
You can't send private messages.
You can't send emails.
You can read topics.
You can't vote in polls.
You can't upload attachments.
You can download attachments.
You can't post HTML code.
You can't edit HTML code.
You can't post IFCode.
You can't post JavaScript.
You can post emoticons.
You can't post or upload images.

Select a forum

































































































































































SQLServerCentral


Search