Looping through fields in a cursor

  • I have a cursor looping through the records of a derived table (or temporary table), I now need to loop through the individual fields in each record... how can this be done... or better yet, can you use COL_NAME(OBJECT_ID('table_name'), @counter) on a temporary table??? and how???

  • COL_NAME can be used to retrieve the column names of temporary tables using following syntax.

    USE TEMPDB

    SELECT COL_NAME(object_id("tempdb..#temp_table"),2)

    where #temp_table is the name of temporary table. The above sql returns 2nd column name.

    Hope this helps

  • Thank you!!! That was a lot less painful than I imagined!

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

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