Looping SQL Process To Select n rows from SQL Table

  • Hi Guys,

    I love this Forum really good especially for a Learner like me.

    This is important and I need a quick solution. Pls note I am working on SQL Server 2000.

    I have a SQL table with 2M rows which we are migrating to SAP system but due to limitation in SAP which accepts text files with only 9999 rows.

    So I want an automated process which will loop through a SQL table pick the Top 9999 and dump it on a text file in a network and then loop the table again to pick the next 9999 and so on until the source exhaust.

    I have created a DTS Package to assist in this where created a transformation with source and destination (text file) but I am having issues in looping this process. Do i need a VB script to do this? Any one one please suggest?

    my query is:

    Select top 9999 Lotnumber, AutoNum, Itemnumber

    from dbo.MigrationGas

    where Status is null

    Order by AutoNum

    Then do an Update query with Status = 1 for the one already selected but what should be my query:

    Thanks in Advance

    Arun

  • It would be a whole lot easier if you could use xp_CmdShell and BCP in a T-SQL loop. Are you allowed to use xp_CmdShell?

    --Jeff Moden


    RBAR is pronounced "ree-bar" and is a "Modenism" for Row-By-Agonizing-Row.
    First step towards the paradigm shift of writing Set Based code:
    ________Stop thinking about what you want to do to a ROW... think, instead, of what you want to do to a COLUMN.

    Change is inevitable... Change for the better is not.


    Helpful Links:
    How to post code problems
    How to Post Performance Problems
    Create a Tally Function (fnTally)

Viewing 2 posts - 1 through 1 (of 1 total)

You must be logged in to reply to this topic. Login to reply