Last active
November 8, 2017 19:03
-
-
Save plaisted/9d127ea81b63bfd59c427805fe31603f to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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