Home Forums SQL Server 2008 SQL Server 2008 - General Use of cursor in ETL stored procedure for moving data from one table to many tables RE: Use of cursor in ETL stored procedure for moving data from one table to many tables

  • somanath_kolekar (9/17/2012)


    Hello All,

    I am beginner to writing stored procedure. So checking out your views on implementing below requirement:

    I have one table containing data in one system. I want to write stored procedure which will move data from this table to 7 tables based on columns mapping.

    I need to some validations while moving data like searching if the record already exists in the destinations tables, rejecting records based on some conditions and moving rejected records to rejected table.

    I started implementing this code with stored procedure alone. However I see that I am not able to check the conditions row-wise and insert\update based on condition when I use only stored procedure.

    I am thinking of using cursor in a stored procedure to apply the logic row-wise.

    This procedure will not be used frequently, however I am wondering if using cursor is the right approach to implement this requirement or are there any better approaches to write code for such requirement.

    Any help is appreciated!!!

    Thanks,

    Somanath

    Hi Somanath,

    How are you validating the data means there must be some primary key or unique value column.You can validate data against that and apply UPINSERT logic.

    --rhythmk
    ------------------------------------------------------------------
    To post your question use below link

    https://www.sqlservercentral.com/articles/forum-etiquette-how-to-post-datacode-on-a-forum-to-get-the-best-help
    🙂