Posted By

rengber on 12/07/06


Tagged

sql CodeGeneration


Versions (?)

Who likes this?

1 person have marked this snippet as a favorite

davidlee


SQL Stored Proc to Generate a list of C# constants representing data field names.


 / Published in: C#
 

  1. SELECT 'public const string COLUMN_' + UPPER(col.TABLE_NAME) + '_' + UPPER(col.COLUMN_NAME) + ' = "' + col.COLUMN_NAME + '";' As [Name]
  2. FROM INFORMATION_SCHEMA.COLUMNS col
  3. INNER JOIN INFORMATION_SCHEMA.TABLES tab ON tab.TABLE_NAME = col.TABLE_NAME
  4. WHERE tab.TABLE_TYPE = 'BASE TABLE'
  5. AND tab.TABLE_NAME NOT IN ('dtproperties', 'sysdiagrams')
  6.  
  7. UNION
  8.  
  9. SELECT 'public const string TABLE_' + UPPER(tab.TABLE_NAME) + ' = "' + tab.TABLE_NAME + '";' As sName
  10. FROM INFORMATION_SCHEMA.TABLES tab
  11. WHERE tab.TABLE_TYPE = 'BASE TABLE'
  12. AND tab.TABLE_NAME NOT IN ('dtproperties', 'sysdiagrams')
  13. ORDER BY [Name] ASC

Report this snippet  

You need to login to post a comment.