Skip to content

Instantly share code, notes, and snippets.

@plaisted
Last active November 8, 2017 19:03
Show Gist options
  • Save plaisted/9d127ea81b63bfd59c427805fe31603f to your computer and use it in GitHub Desktop.
Save plaisted/9d127ea81b63bfd59c427805fe31603f to your computer and use it in GitHub Desktop.
declare @tableName varchar(200)
declare @enumInt int
declare @enumName varchar(50)
declare @enum varchar(200)
set @tableName = 'TableName'
DECLARE table_cursor CURSOR FOR
SELECT IntColumn, StringNameColumn
FROM TableName
PRINT 'public enum ' + @tableName + ' {'
OPEN table_cursor
FETCH NEXT FROM table_cursor INTO @enumInt, @enumName
WHILE @@FETCH_STATUS = 0
BEGIN
SELECT @enum = ' ' + @enumName + ' = ' + cast(@enumInt as varchar(3)) + ','
FETCH NEXT FROM table_cursor INTO @enumInt, @enumName
IF @@FETCH_STATUS != 0
BEGIN
SELECT @enum = LEFT(@enum, LEN(@enum) - 1)
PRINT @enum
END
ELSE
BEGIN
PRINT @enum
END
END
print '}'
print ''
CLOSE table_cursor
DEALLOCATE table_cursor
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment