We Recommend

Accelerated C# 2008 Accelerated C# 2008
This book is both a rapid tutorial and a permanent reference. You’ll quickly master C# syntax while learning how the CLR simplifies many programming tasks. You’ll also learn best practices that ensure your code will be efficient, reusable, and robust. Why spend months or years discovering the best ways to design and code C# when this book will show you how to do things the right way, right from the start?


Posted By

rengber on 12/07/06


Tagged

sql CodeGeneration


Versions (?)


Who likes this?

1 person has 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.