DECLARE @TableName VARCHAR(20) = 'tblFileType' -------------> type table name
DECLARE @ValueField VARCHAR(20) = 'Id' -------------> type ValueField Name
DECLARE @NameField VARCHAR(20) = 'Name' -------------> type NAme Field Name
BEGIN
DECLARE @SqlQuery VARCHAR(MAX) =
'SELECT ''public enum enum' + REPLACE( @TableName, 'tbl', '') + ''' AS enum
UNION ALL
SELECT ''{''
UNION ALL
SELECT ( REPLACE(' + @NameField + ', '' '', '''') + '' = '' + CAST( ' + @ValueField + ' AS VARCHAR(10) ) ) + '','' FROM ' + @TableName
+ ' UNION ALL SELECT ''}'' '
PRINT @SqlQuery
EXECUTE( @SqlQuery )
-- SELECT Name + ' = ' + CAST( Id AS VARCHAR(10) ) + ',' FROM tblUserRoll
END