Please start any new threads on our new site at https://forums.sqlteam.com. We've got lots of great SQL Server experts to answer whatever question you can come up with.

 All Forums
 SQL Server 2005 Forums
 SSIS and Import/Export (2005)
 To pick the rows one by one in a variable

Author  Topic 

notes4we
Yak Posting Veteran

90 Posts

Posted - 2009-04-08 : 09:28:34
I have a table1 with two datetime columns - StartDate and EndDate and few other columns like ID, etc.

I want to use all the datetimes that are in the startdate column and the enddate column in the following query which I am planning to use in the Execute SQL Task.

SELCT * FROM TableName
WHERE StartDate between '2008-05-07 00:00:00.000' and '2008-05-07 08:30:00.000'

Now, in this query, where there is StartDate between '2008-05-07 00:00:00.000' and '2008-05-07 08:30:00.000'

I want to use table1 to get the values. The values should be stored in a variable and one by one the values should be selected and placed in place of these dates.

Which task or container will help me to loop through these rows and get the dates. If you answer is the ForeachLoopContainer, then please let me know the steps also. I am not good at using ForeachLoops, so.

If you do not understand my question, please do let me know. I am kind of stuck in this issue, so please help me if you can.

rgombina
Constraint Violating Yak Guru

319 Posts

Posted - 2009-04-08 : 09:37:09
Are you trying to pass each date to SQL Task to do more query? I ask because you could combine tasks to get desired result without looping.
Go to Top of Page

notes4we
Yak Posting Veteran

90 Posts

Posted - 2009-04-08 : 09:47:37
I want to use this query again and again for all the different startdates that are in the table. I mean, in one package, in one task itself, I want to use this query but with different dates as specified in the table.
Go to Top of Page

rgombina
Constraint Violating Yak Guru

319 Posts

Posted - 2009-04-08 : 10:35:05
Looks like this can be accomplished using Stored Proc. Let's have SQL gurus give their take on this topic.
Go to Top of Page

YellowBug
Aged Yak Warrior

616 Posts

Posted - 2009-04-09 : 14:11:14
You could use the ForEachLoop, select Foreach ADO Enumerator to loop through a recordset.
Here's a step-by-step guide: http://www.sqlis.com/post/Shredding-a-Recordset.aspx

If you plan on using the values in the Execute SQL Task only, then a stored procedure solution may be best.
Go to Top of Page
   

- Advertisement -