The sp_for procedure provides simple single-statement loop processing for T-SQL statements, similar to the FOR command in the C language or the DOS command-line utility by the same name.
It's syntax is similar to that of the DOS command. It takes an argument to represent a variable, initialize the variable, set an increment, set an end point, and a T-SQL command to run during the duration of the loop.
EXEC sp_for '@i', 1, 1, 5, 'PRINT OBJECT_NAME(@i)'
The above example would print the object names of all objects in the current database with an id between 1 and 5. Although this would not be the most efficient way to do this specific operation (a set-oriented approach whould be better here), I have included this merely as an example.
Creating a PDF from a Stored Procedure in SQL Server
A short but interesting article, the author has figured out a way to create a PDF from a stored procedure without using a third party library.
2019-09-20 (first published: 2003-08-26)
73,114 reads