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 123»»»

Real World Foreach Loop Container example Expand / Collapse
Author
Message
Posted Saturday, February 23, 2008 1:44 PM
SSC Rookie

SSC RookieSSC RookieSSC RookieSSC RookieSSC RookieSSC RookieSSC RookieSSC Rookie

Group: General Forum Members
Last Login: Thursday, September 18, 2014 12:01 PM
Points: 43, Visits: 191
Comments posted to this topic are about the item Real World Foreach Loop Container example
Post #459462
Posted Monday, February 25, 2008 9:48 AM
SSC-Enthusiastic

SSC-EnthusiasticSSC-EnthusiasticSSC-EnthusiasticSSC-EnthusiasticSSC-EnthusiasticSSC-EnthusiasticSSC-EnthusiasticSSC-Enthusiastic

Group: General Forum Members
Last Login: Friday, September 26, 2014 9:54 AM
Points: 181, Visits: 687
Great article. I was just about to send a very similar article for submission. Guess you beat me to it:)
Post #459794
Posted Monday, February 25, 2008 3:26 PM


Valued Member

Valued MemberValued MemberValued MemberValued MemberValued MemberValued MemberValued MemberValued Member

Group: General Forum Members
Last Login: Sunday, May 22, 2011 6:15 PM
Points: 65, Visits: 80
I second that. The for each loops are a great tool. I use one with variables and script for looping through database backups on my main server to grab the latest dated ones and FTP them over to a secondary backup server (no I'm not really paranoid about losing data!)





Best Regards
Terry
Post #459999
Posted Tuesday, February 26, 2008 12:39 AM


Forum Newbie

Forum NewbieForum NewbieForum NewbieForum NewbieForum NewbieForum NewbieForum NewbieForum Newbie

Group: General Forum Members
Last Login: Tuesday, February 26, 2008 3:18 AM
Points: 2, Visits: 6
Sorry ;)


Post #460086
Posted Wednesday, February 27, 2008 9:14 AM
SSC-Enthusiastic

SSC-EnthusiasticSSC-EnthusiasticSSC-EnthusiasticSSC-EnthusiasticSSC-EnthusiasticSSC-EnthusiasticSSC-EnthusiasticSSC-Enthusiastic

Group: General Forum Members
Last Login: Sunday, January 13, 2013 10:55 AM
Points: 166, Visits: 417
Just came across your article and fine it very useful tools for me to learn sqlis. I have a problem with Execute SQL Task in the loop container:
Insert into tmpTlogFileList(FileName)values(@FileName):
Execute SQL Task: Executing the query "insert into tmpTlogFileList (FileName) values (@FileName)" failed with the following error: "Must declare the scalar variable "@FileName".".

Must I declare @Filename as nvarchar(128) from the sql statement?

thanks



Post #460978
Posted Wednesday, February 27, 2008 9:39 AM
SSC Rookie

SSC RookieSSC RookieSSC RookieSSC RookieSSC RookieSSC RookieSSC RookieSSC Rookie

Group: General Forum Members
Last Login: Thursday, September 18, 2014 12:01 PM
Points: 43, Visits: 191
Right-click your "Execute SQL Task". In the "Execute SQL Task Editor", go to Parameter Mapping. Add a parameter as follows:

Variable Name - User::varTLogFileName
Direction - Input
Data Type - String
Parameter Name - @FileName
Parameter Size: -1

Hope this is now clear. Best of luck!
Post #461012
Posted Wednesday, February 27, 2008 10:22 AM
SSC-Enthusiastic

SSC-EnthusiasticSSC-EnthusiasticSSC-EnthusiasticSSC-EnthusiasticSSC-EnthusiasticSSC-EnthusiasticSSC-EnthusiasticSSC-Enthusiastic

Group: General Forum Members
Last Login: Sunday, January 13, 2013 10:55 AM
Points: 166, Visits: 417
Paul,

I get the same error...Here are a bit more detail on execute sql task:
General tab:
resultset: None
connectionType: OLE DB
connection: UserServerConnection
sqlsourceType: Direct input
sqlstatement: insert into tmpTLogFileList(FileName) values (@FileName)
bypassPrepare: True

The Parameter Mapping is same above as you mention, except
for Data Type - Nvarchar, I can't fine the dropdown for String.

I appreciate all you help thanks....

Error: 0xC002F210 at Execute SQL Task, Execute SQL Task: Executing the query "insert into tmpTLogFileList(FileName) values (@FileName)" failed with the following error: "Must declare the scalar variable "@FileName".". Possible failure reasons: Problems with the query, "ResultSet" property not set correctly, parameters not set correctly, or connection not established correctly.
Task failed: Execute SQL Task




Post #461085
Posted Wednesday, February 27, 2008 4:24 PM


Valued Member

Valued MemberValued MemberValued MemberValued MemberValued MemberValued MemberValued MemberValued Member

Group: General Forum Members
Last Login: Sunday, May 22, 2011 6:15 PM
Points: 65, Visits: 80
tran008,

I think you need to provide a bit more basic information about what you are trying to do. Where are you getting the @FileName parameter from anyway? My thoughts are that it should be declared as a User::[varname] in the for each loop and then this mapped across to the parameter in the SQL Task, but without knowing what it is you are trying to do it is hard to be of more assistance.




Best Regards
Terry
Post #461349
Posted Wednesday, February 27, 2008 5:09 PM


Valued Member

Valued MemberValued MemberValued MemberValued MemberValued MemberValued MemberValued MemberValued Member

Group: General Forum Members
Last Login: Sunday, May 22, 2011 6:15 PM
Points: 65, Visits: 80
As an after thought - depending on what you wish to do of course, you may have to execute the sql statement as a variable. Out of curiosity I just put together a for each loop to save a series of .txt files into a table and this worked well by using a variable for the sql statement. Let me know if you want any further detail on this method.



Best Regards
Terry
Post #461361
Posted Thursday, February 28, 2008 3:03 PM
SSC-Enthusiastic

SSC-EnthusiasticSSC-EnthusiasticSSC-EnthusiasticSSC-EnthusiasticSSC-EnthusiasticSSC-EnthusiasticSSC-EnthusiasticSSC-Enthusiastic

Group: General Forum Members
Last Login: Sunday, January 13, 2013 10:55 AM
Points: 166, Visits: 417
thanks...I finally figure this out after long search.

OleDB...connection.

INSERT INTO tempTlogFileList
(FileName)
VALUES (?)

instead of
INSERT INTO tempTlogFileList
(FileName)
VALUES (@FileName)



Post #462020
« Prev Topic | Next Topic »

Add to briefcase 123»»»

Permissions Expand / Collapse