Click here to monitor SSC
SQLServerCentral is supported by Red Gate Software Ltd.
 
Log in  ::  Register  ::  Not logged in
 
 
 
        
Home       Members    Calendar    Who's On


Add to briefcase

Foreach and Variables... Expand / Collapse
Author
Message
Posted Wednesday, January 7, 2009 2:44 PM
Forum Newbie

Forum NewbieForum NewbieForum NewbieForum NewbieForum NewbieForum NewbieForum NewbieForum Newbie

Group: General Forum Members
Last Login: Monday, April 2, 2012 2:49 PM
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)
Post #631921
Posted Wednesday, January 7, 2009 2:55 PM
SSC Veteran

SSC VeteranSSC VeteranSSC VeteranSSC VeteranSSC VeteranSSC VeteranSSC VeteranSSC Veteran

Group: General Forum Members
Last Login: Monday, December 15, 2014 5:30 PM
Points: 226, Visits: 730
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
Post #631933
Posted Wednesday, January 7, 2009 3:05 PM
Forum Newbie

Forum NewbieForum NewbieForum NewbieForum NewbieForum NewbieForum NewbieForum NewbieForum Newbie

Group: General Forum Members
Last Login: Monday, April 2, 2012 2:49 PM
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.

Post #631938
Posted Wednesday, January 7, 2009 3:09 PM
Forum Newbie

Forum NewbieForum NewbieForum NewbieForum NewbieForum NewbieForum NewbieForum NewbieForum Newbie

Group: General Forum Members
Last Login: Monday, April 2, 2012 2:49 PM
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.
Post #631940
Posted Wednesday, January 7, 2009 3:19 PM
SSC Veteran

SSC VeteranSSC VeteranSSC VeteranSSC VeteranSSC VeteranSSC VeteranSSC VeteranSSC Veteran

Group: General Forum Members
Last Login: Monday, December 15, 2014 5:30 PM
Points: 226, Visits: 730
What is the datatype of your SSIS variable? If its Int32 try to use LONG as datatype in Parameter mappings.
Post #631948
Posted Wednesday, January 7, 2009 3:25 PM
Forum Newbie

Forum NewbieForum NewbieForum NewbieForum NewbieForum NewbieForum NewbieForum NewbieForum Newbie

Group: General Forum Members
Last Login: Monday, April 2, 2012 2:49 PM
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.
Post #631954
Posted Wednesday, January 7, 2009 4:14 PM
SSC Veteran

SSC VeteranSSC VeteranSSC VeteranSSC VeteranSSC VeteranSSC VeteranSSC VeteranSSC Veteran

Group: General Forum Members
Last Login: Monday, December 15, 2014 5:30 PM
Points: 226, Visits: 730
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.
Post #631986
« Prev Topic | Next Topic »

Add to briefcase

Permissions Expand / Collapse