I am trying to achieve something along the lines of a for-each, where I would like to take the Ids of a returned select statement and use each of them.
DECLAR
The following line is wrong in your version:
WHILE (@i <= (SELECT MAX(idx) FROM @Practitioner))
(Missing the @)
Might be an idea to change your naming convention so that the tables are more different.