1

I have table with columns Start date and end date and i need to enter values for 2 years.I created a for loop and I am trying to load values for every month.

For Example, My first input start Date is 10/12/2016 end date 11/11/2016. It should be incremented with one month and inserted into table for 2 years.

For Loop Container

InitExpression: @windowStart="10/12/2016"

Evalexpression: @WindowStart<@windowMaxdate

AssignExpression: @windowStart= Dateadd("mm",1,@windowStart)

Execute sql task

SQL command:

Insert into dbo.datetemp 
(WindowStart,WindowEnd ) values (?,?)

My problem is i am not getting values what i am expected and its just returning same windowstart and windowend for every record. And loop is not coming to stop.

enter image description here

Hadi
  • 34,224
  • 11
  • 61
  • 121

2 Answers2

1

Guys i got the solution.

I have added a expression task inside for loop after execute sql task

@[User::WindowStart] = (DT_WSTR,24)(DT_DBTIMESTAMP) dateadd("mm",1, 
(@[User::WindowStart]) )

instead adding this expression in Assign expression in for loop editor.

0

You are passing a string value to a @windowStart.

Create a variable @StartDate of type Datetime with the value 2016-12-10. And use the following expression:

InitExpression: @windowStart= @StartDate

Also make sure that @windowStart and @windowMaxdate are of type DateTime

Also check this similar question for more information:

Hadi
  • 34,224
  • 11
  • 61
  • 121
  • its the same thing i am getting only one record into table. and the loop is not stoping execution. where execute sql task inserted only one record. – sai yarlagadda Aug 17 '18 at 18:57