• jancas08 (2/27/2013)


    For example, the select statements finds 10 rows that contain 'UPDATE', it would do the sql execution on the 10 rows that contain 'UPDATE'. But, the use of printing the statement will only show the last row that contain 'UPDATE' because print can't multiple rows in a single instance.

    Still not really sure what you are saying. There is only 1 row of dynamic sql now, it contains multiple statements. The code I posted did not have a print statement because there is no loop.

    print @CORRECTION_STATEMENT

    That will show the entire sql that is going to be executed. It will contain multiple statements now instead of one at a time.

    _______________________________________________________________

    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/