Posted by Adam Buenz
So, today one of my friends asked me if I knew how to return the names of all the fields in a table using a stored procedure so that he could build the names into a generic string collection. This is how you do it:
SQL:
-
CREATE PROCEDURE [dbo].[GetColumnNames] @tableName VARCHAR(50)
-
AS
-
SELECT name
-
FROM syscolumns
-
WHERE id = OBJECT_ID(@tableName)
Easy as pie!










