Solved

Do While Loops Works in TSQL but not SSIS

Posted on 2013-06-26
5
485 Views
Last Modified: 2016-02-11
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
Comment
Question by:Gary Harper
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 3
  • 2
5 Comments
 
LVL 35

Expert Comment

by:David Todd
ID: 39280574
Hi,

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

Regards
  David
0
 

Author Comment

by:Gary Harper
ID: 39290539
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
 
LVL 35

Accepted Solution

by:
David Todd earned 500 total points
ID: 39291239
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
 

Author Comment

by:Gary Harper
ID: 39291245
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
 
LVL 35

Expert Comment

by:David Todd
ID: 39291383
Hi,

Do you need further help?

Regards
  David
0

Featured Post

Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

My client has a dictionary table. They're defining a list of standard naming convention. Now, they are requiring my team to provide us a mechanism how to match new incoming data with existing data in their system.
Ever needed a SQL 2008 Database replicated/mirrored/log shipped on another server but you can't take the downtime inflicted by initial snapshot or disconnect while T-logs are restored or mirror applied? You can use SQL Server Initialize from Backup…
In this video, viewers are given an introduction to using the Windows 10 Snipping Tool, how to quickly locate it when it's needed and also how make it always available with a single click of a mouse button, by pinning it to the Desktop Task Bar. Int…
In this brief tutorial Pawel from AdRem Software explains how you can quickly find out which services are running on your network, or what are the IP addresses of servers responsible for each service. Software used is freeware NetCrunch Tools (https…

623 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question