Okay, I've searched around and seen some things that are *kinda* like what I want to do, but can't seem to figure out enough from those examples to put it all together, especially the iteration through the blocks.

I need to run SQL queries based on the page number of wiring diagrams (each page contains different information). There is a "PAGE_NO" attribute in each border block, with as many as 6 or 8 pages per drawing. What I need is to iterate through the title blocks and run the query for each page, with the PAGE_NO attribute value being applied to it's particular query string. Once that's done, I'll need to update the REV attribute based on the results of the query.

I think I need to:

1. Create a list of the relevant blocks in the drawing.

Code:
(if (setq ss (ssget "_X"
              (list (cons 0 "INSERT")
                (cons 2 "*BORDER*")
                (cons 66 1)
              )
           )
      )
(OTHER CODE HERE)
    (princ "\n<!> No Block Found <!>")
  )
2. Dig down into each one and get the value of the "PAGE_NO" attribute.
I don't know how to do this without applying it to the whole list.
3. Apply the value found to the SQL statement.

Code:
(setq wdpg1 (strcat "SELECT level FROM revisions WHERE (item = '"fld1"') AND (document = 'Wiring Diagram>pg 1')"))
4. Apply query results to the "REV" attribute.
I know how to apply the results to a variable, but I don't know how to apply the variable to the REV attribute to the border of that particular PAGE_NO.

5. Repeat for remaining pages.
Code:
(foreach x ... something or another...

Any guidance would be greatly appreciated.

Thanks