title: Print list of tables with option sets
body: <p>I would like to print a list of 200 reference table names (refTableA, refTableB, etc) along with the option sets for each table (refTableAID, Description, Code, SortOrder). Some option sets are a single record; others may include over 30 records. 
  The script below inserts the Description, Code and SortOrder data into a temp table. I am stumped on how to insert the name of the table (refTableA) into the RefTableName field and the ID (RefTableAID) into the RefTableNameId field. Any help is greatly appreciated.</p>
  
  <pre><code>IF OBJECT_ID('tempdb..#Temp') IS NOT NULL DROP TABLE #Temp
  DECLARE @table nvarchar(150) 
  DECLARE @sqlinsert nvarchar(max)
  DECLARE C1 CURSOR FOR SELECT TABLE_NAME FROM  Information_schema.tables where TABLE_NAME like 'ref%'
  
  Create table #Temp
  (
  RefTableName nvarchar(150),
  RefTableNameId int,
  Description nvarchar(100),
  Code nvarchar(50),
  SortOrder Decimal(5,2)
  )
  
  OPEN C1
  FETCH next FROM C1 INTO @table
  WHILE @@FETCH_STATUS =0
  BEGIN
    set @sqlinsert='Insert into #Temp (Description, Code, SortOrder) 
      Select Description,Code,SortOrder from *tbl*'       
    set @sqlinsert = REPLACE(@sqlinsert,'*tbl*',@table)
    Print (@sqlinsert)
    Exec (@sqlinsert)   
  FETCH next FROM C1 INTO @table
  END
  CLOSE C1
  DEALLOCATE C1
  SELECT * from #Temp
  </code></pre>