Cursors for SQl server

  • Hi,

    i have task where i need to update the 2 columns from 2 different tables.I need to get one column from one table and update to the other table.If the column name do not match....Please help

  • bpsavi123 (5/15/2015)


    Hi,

    i have task where i need to update the 2 columns from 2 different tables.I need to get one column from one table and update to the other table.If the column name do not match....Please help

    Hi and welcome to SSC. We can help but we need some information. And for the record we will want to avoid cursors in nearly every situation as they are horrible for performance.

    To help you with your current problem please take a look at the first link in my signature for best practices when posting questions.

    _______________________________________________________________

    Need help? Help us help you.

    Read the article at http://www.sqlservercentral.com/articles/Best+Practices/61537/ for best practices on asking questions.

    Need to split a string? Try Jeff Modens splitter http://www.sqlservercentral.com/articles/Tally+Table/72993/.

    Cross Tabs and Pivots, Part 1 – Converting Rows to Columns - http://www.sqlservercentral.com/articles/T-SQL/63681/
    Cross Tabs and Pivots, Part 2 - Dynamic Cross Tabs - http://www.sqlservercentral.com/articles/Crosstab/65048/
    Understanding and Using APPLY (Part 1) - http://www.sqlservercentral.com/articles/APPLY/69953/
    Understanding and Using APPLY (Part 2) - http://www.sqlservercentral.com/articles/APPLY/69954/

  • bpsavi123 (5/15/2015)


    Hi,

    i have task where i need to update the 2 columns from 2 different tables.I need to get one column from one table and update to the other table.If the column name do not match....Please help

    I have to agree with Sean. Really can't help you with what little info you provided. Also, cursors have their uses but in this case it may not be the correct option.

  • As others said, more details: good, cursor for this: bad.

    It sounds like you can accomplish what you are trying to do with two update statements.

    "I cant stress enough the importance of switching from a sequential files mindset to set-based thinking. After you make the switch, you can spend your time tuning and optimizing your queries instead of maintaining lengthy, poor-performing code."

    -- Itzik Ben-Gan 2001

  • bpsavi123 (5/15/2015)


    Hi,

    i have task where i need to update the 2 columns from 2 different tables.I need to get one column from one table and update to the other table.If the column name do not match....Please help

    Update using a WHERE NOT EXISTS using a correlated sub-query of the two tables.

    --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 5 posts - 1 through 4 (of 4 total)

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