Showing posts with label loop. Show all posts
Showing posts with label loop. Show all posts

Thursday, March 8, 2012

Can I use the foreach loop to obtain the sub folder names within a folder?

I have a set of folders with the following structure:

MainFolder

1999

SpreadsheetA.xls

SpreadsheetB.xls

SpreadsheetC.xls

2000

SpreadsheetA.xls

SpreadsheetB.xls

SpreadsheetC.xls

etc.

Is there a way that I can use the foreach loop container to loop the sub folders? My plan was to get the folder name and path into a variable, use this to build the connection string for each file in this folder, carry out the upload for that folder, then move onto the next folder and do the same thing, but I cannot see a way to do this.

Thanks,

Sam

If the list of folders is known and finite then you can just type them into the ForEach Item Enumerator.

If the list changes then you'll need to do something a bit cleverer. Like writing your own Enumerator.

-Jamie

|||

sam2005 wrote:

I have a set of folders with the following structure:

MainFolder

1999

SpreadsheetA.xls

SpreadsheetB.xls

SpreadsheetC.xls

2000

SpreadsheetA.xls

SpreadsheetB.xls

SpreadsheetC.xls

etc.

Is there a way that I can use the foreach loop container to loop the sub folders? My plan was to get the folder name and path into a variable, use this to build the connection string for each file in this folder, carry out the upload for that folder, then move onto the next folder and do the same thing, but I cannot see a way to do this.

Thanks,

Sam


Have you tried the 'traverse sub folders' option on the ForEach object (on the collection pane)

Friday, February 24, 2012

Can I store the result set of sp_who command in a table

Hi,
I want to loop through the records of the result set of sp_who.
Can this be done? How it can be done?
Regards,
Sevugan.C
code:

create table #tmpSpWho
(
spid smallint
,ecid smallint
,status nchar(30)
,loginame nchar(128)
,hostname nchar(128)
,blk char(5)
,dbname nchar(128)
,cmd nchar(16)
)
insert into #tmpSpWho
exec sp_who


HTH,
Cristian Lefter, SQL Server MVP
"Sevugan" <
Sevugan@.discussions.microsoft.com>
wrote in message
news:41413280-9A1A-481D-9FC8-31642E546811@.microsoft.com...
>
Hi,
>
I want to loop through the records of the result set of sp_who.
>
Can this be done? How it can be done?
>
>
Regards,
>
>
Sevugan.C|||You can create a temporary table to grab the result from the sp sp_who2.
Example:
use northwind
go
create table #t1 (
spid int,
status varchar(255),
login sysname,
hostname sysname,
blkby sysname,
dbname varchar(128),
command varchar(255),
cputime int,
diskio int,
lastbatch varchar(35),
programname varchar(128),
spid_1 int
)
go
insert into #t1
exec sp_who2
go
select
*
from
#t1
order by
login
go
drop table #t1
go
AMB
"Sevugan" wrote:

> Hi,
> I want to loop through the records of the result set of sp_who.
> Can this be done? How it can be done?
> Regards,
> Sevugan.C|||If you are wanting to do this on the client side, you can call sp_who into
an ADO recordset the same as any stored procedure.
"Sevugan" <Sevugan@.discussions.microsoft.com> wrote in message
news:41413280-9A1A-481D-9FC8-31642E546811@.microsoft.com...
> Hi,
> I want to loop through the records of the result set of sp_who.
> Can this be done? How it can be done?
> Regards,
> Sevugan.C|||Create TABLE #WHO
(
spid int,
ecid int,
Status Nvarchar(20),
LoginName Nvarchar(30),
Hostname Nvarchar(30),
blk int,
dbname Nvarchar(30),
cmd Nvarchar(255)
)
Insert #who
EXEC sp_who
Select * from #who
Create cursor to loop through data with whatever you want to do with the dat
a.
Hope this helps.
"Sevugan" wrote:

> Hi,
> I want to loop through the records of the result set of sp_who.
> Can this be done? How it can be done?
> Regards,
> Sevugan.C

Friday, February 10, 2012

Can I loop through table and run reports from SSIS

I would like to loop through a SQL Server table that contains the paths to all the reports we need to run and then execute the reports via SSIS. What task should I be doing to do this? Will the For Loop work for something like this?Yes, you can use the ForEach loop to iterate through the resultset of a query.

So you would use an Execute SQL task to select your report URLs and place them in an object variable. You can iterate through those resultset rows in a ForEach ADO Enumerator loop and place values of the columns into variables. Then inside the loop you would use a script task to make a WebRequest to SSRS with a URL you constructed from the variables. You can then write the stream from the WebResponse to a file.

Hopefully you are planning to render these reports to a binary format such as Excel or PDF instead of HTML. HTML reports generally comprise multiple HTTP streams and cannot be easily executed without a browser.
|||

Actually I am running Cognos reports so I would need to build the cmd line command and execute an executable from a command prompt.

Any example of the above on the web?

|||You can run an executable through the Execute Process Task.|||

agentf1 wrote:

Actually I am running Cognos reports so I would need to build the cmd line command and execute an executable from a command prompt.

Any example of the above on the web?

Oh, I shouldn't have assumed SSRS. Running from the command prompt makes it easier. That changes the above so that you'd have another variable that is expression-based to construct your command line, then use an Execute Process instead of script. No code at all.

http://sqljunkies.com/WebLog/knight_reign/archive/2005/03/25/9588.aspx
http://blogs.conchango.com/jamiethomson/archive/2005/07/04/1748.aspx

http://blogs.conchango.com/jamiethomson/archive/2005/03/19/SSIS_3A00_-Evaluating-variables-as-expressions.aspx

|||

Hi JayH

My Name is Praveen . Could you please explain how it could be done in detail . It would be very helpful if send an answer to it .Especially the scripting part i didnt understand anything

|||I would like to loop through a SQL Server table that contains the paths to all the reports we need to run and then execute the reports(SSRS) via SSIS. What task should I be doing to do this? Could you explain in detail

Can I loop through table and run reports from SSIS

I would like to loop through a SQL Server table that contains the paths to all the reports we need to run and then execute the reports via SSIS. What task should I be doing to do this? Will the For Loop work for something like this?Yes, you can use the ForEach loop to iterate through the resultset of a query.

So you would use an Execute SQL task to select your report URLs and place them in an object variable. You can iterate through those resultset rows in a ForEach ADO Enumerator loop and place values of the columns into variables. Then inside the loop you would use a script task to make a WebRequest to SSRS with a URL you constructed from the variables. You can then write the stream from the WebResponse to a file.

Hopefully you are planning to render these reports to a binary format such as Excel or PDF instead of HTML. HTML reports generally comprise multiple HTTP streams and cannot be easily executed without a browser.
|||

Actually I am running Cognos reports so I would need to build the cmd line command and execute an executable from a command prompt.

Any example of the above on the web?

|||You can run an executable through the Execute Process Task.|||

agentf1 wrote:

Actually I am running Cognos reports so I would need to build the cmd line command and execute an executable from a command prompt.

Any example of the above on the web?

Oh, I shouldn't have assumed SSRS. Running from the command prompt makes it easier. That changes the above so that you'd have another variable that is expression-based to construct your command line, then use an Execute Process instead of script. No code at all.

http://sqljunkies.com/WebLog/knight_reign/archive/2005/03/25/9588.aspx
http://blogs.conchango.com/jamiethomson/archive/2005/07/04/1748.aspx

http://blogs.conchango.com/jamiethomson/archive/2005/03/19/SSIS_3A00_-Evaluating-variables-as-expressions.aspx

|||

Hi JayH

My Name is Praveen . Could you please explain how it could be done in detail . It would be very helpful if send an answer to it .Especially the scripting part i didnt understand anything

|||I would like to loop through a SQL Server table that contains the paths to all the reports we need to run and then execute the reports(SSRS) via SSIS. What task should I be doing to do this? Could you explain in detail