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)
 does the while begin loop work in ssis?

Author  Topic 

dlorenc
Posting Yak Master

172 Posts

Posted - 2009-07-28 : 13:48:40
The code below is intended to count the on time deliveries per month, beginning in july of 2008. In sql mgmt studio, the code works, and drop out 13 records with the aggregate data.

when I drop the same code into a ssis dataflow task, by putting the code in the sql option for the ole db source object, it only completes the first loop..dropping only the july '08 record into the target table....

HELP!

---------------------------------------------------------------------

-- This code will start in FY09 and count the ontime delivery per month, and calculate the percentage of ontime deliveries.

declare @monthstart datetime,@monthend datetime,@ReportPeriod varchar(15),@StartDate datetime, @loop int

set @StartDate = '7/2/2008'

set @loop = datediff(mm,@StartDate, getdate())+1 -- 13 loops

While @loop >0
begin

set @MonthStart = DATEADD(mm, DATEDIFF(mm,0,@StartDate), 0)
set @MonthEnd = DATEADD(s,-1,DATEADD(m,1,@MonthStart))

--select @monthstart, @monthend,@reportdate

declare @x float,@y float;

select @x = count(*) -- OnTime
,@ReportPeriod = substring(CONVERT(VARCHAR(11), @monthstart, 106),4,11)
FROM HPD_HelpDesk
WHERE dateadd(s,resolved_time,'19700101') between @MonthStart and @MonthEnd
and datediff(hh,dateadd(s,Create_Time,'19700101'),dateadd(s,resolved_time,'19700101'))/24.<=5

select @y = count(*) -- Total
FROM HPD_HelpDesk
WHERE dateadd(s,Create_Time,'19700101')>='2008-07-01 00:00:00'
and dateadd(s,resolved_time,'19700101') between @MonthStart and @MonthEnd

SELECT @ReportPeriod as ReportPeriod
,@x as OnTime
,@y as Total
,case when @y = 0 then 0 else @x/@y end as PercentOntime
,getdate() AS Entered

set @StartDate = @StartDate + 31
set @loop=@loop -1
end
----------------------------------------------------------------
sql mgmt studio will write out 13 records in this format:

ReportPeriod OnTime Total PercentOnTime Entered
Jul 2008 8585 9256 .9275 ... 2009-07-28 12:42:05
Aug 2008 .............
Sep 2008
Oct 2008
.......

dlorenc
Posting Yak Master

172 Posts

Posted - 2009-07-30 : 19:07:10
I determined that ssis does not support multiple result sets..so my loop ..looped..but never wrote anything out except on the first pass..so I got only one record added to the database...

I rewrote the query to produce all months in one record set, and got rid of the loop....
Go to Top of Page
   

- Advertisement -