Hello,
I would like to write some SQL that loops thru the results of a SELECT statement. As an example, if I have a table DEPT with column NAME, I'm guessing the code would look something like below, however I can't get the syntax to work correctly? Thanks
DECLARE @dept_name varchar(20)
for @dept_name in (select NAME from DEPT)
print @dept_name
next
Start Free Trial