• Pritz (3/14/2014)


    Thanks, please consider this one.

    I am newbee on this.

    What I am trying to do is set @rec_num to 0 and then

    Set @Nrec_num = @Nrec_num + 1

    Set @SQLexec = 'Update dbo.voters Set rec_num = '+Cast(@Nrec_num as varchar)+' from dbo.voters where part_no = '+@part_no

    Exec(@SQLexec)

    Can you please help me with this?

    Same concepts as Luis posted previously. Drop the loop and there is absolutely no need to use dynamic sql for this. Probably need ROW_NUMBER for this one but without ddl and sample data it is just guesswork.

    _______________________________________________________________

    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/