Example
/*
The result can be use for fast way to use columns on Insertion/Updates.
Works with tables and views.
Example: eTableColumns 'Customers'
ColumnNames
------------------------------------------------------
Id, FName, LName, Email, PhoneNumber, PreferredContact
INSERT INTO Customers (Id, FName, LName, Email, PhoneNumber, PreferredContact)
VALUES (5, 'Ringo', 'Star', '[email protected]', NULL, 'EMAIL')
*/
CREATE PROCEDURE eTableColumns (@Table VARCHAR(100))
AS
SELECT ColumnNames =
STUFF( (SELECT ', ' + c.name
FROM
sys.columns c
INNER JOIN
sys.types t ON c.user_type_id = t.user_type_id
WHERE
c.object_id = OBJECT_ID( @Table)
FOR XML PATH, TYPE).value('.[1]','varchar(2000)'),
1, 1, '')
GO