Go Premium for a chance to win a PS4. Enter to Win

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 513
  • Last Modified:

Do While Loops Works in TSQL but not SSIS

I am using a DO WHILE loop in tsql to populate two months worth of data with over 150 columns of information.  My query works in TSQL to where it displays all the information but I noticed that it is basically executing the query separately for each day in the two month timeframe.  I am guessing that is why when I try and run this stored procedure in SSIS to populate a new table it just writes the first record then finishes successfully.  I am guessing I should be using another statement besides DO WHILE or doing something different in SSIS?  Any feedback you can provide would be greatly appreciated.  Please advise.
0
Gary Harper
Asked:
Gary Harper
  • 3
  • 2
1 Solution
 
David ToddSenior DBACommented:
Hi,

I wasn't aware that there was a do ... while loop in T-SQL. Can you show us your code?

Regards
  David
0
 
Gary HarperAuthor Commented:
Actually it is a WHILE loop... Attached is a sample of my query... there are several more columns.  What I would like to do is loop through this x number of times and insert all these records into a table by date... How is this possible?
sample-query.txt
0
 
David ToddSenior DBACommented:
Hi,

The problem is that the begin after the while is commented out.

simple while looks like this

declare @days int
set @days = 1

while @days <=  86 begin
    insert dbo.sometable
    select columns
    from dbo.someothertable
    where
        somedayscolumn = @days

    set @days = @days + 1

end

Open in new window


HTH
  David
0
 
Gary HarperAuthor Commented:
That is what I ended up doing since I didn't get a response.  I suppose this is the correct way to do it.
0
 
David ToddSenior DBACommented:
Hi,

Do you need further help?

Regards
  David
0

Featured Post

VIDEO: THE CONCERTO CLOUD FOR HEALTHCARE

Modern healthcare requires a modern cloud. View this brief video to understand how the Concerto Cloud for Healthcare can help your organization.

  • 3
  • 2
Tackle projects and never again get stuck behind a technical roadblock.
Join Now