title: List Column Names in a Table
body: <p>I want to create code that will return all the column names in a table that I can use for other purposes.  I have this code written. </p>
  
  <pre><code>DECLARE @SQLCommand VARCHAR(4000)
  DECLARE @TableName VARCHAR(50)
  SET @TableName = 'ship_to_ud'
  
  SET @SQLCommand = 
  'DECLARE @SelTable VARCHAR(50)
  SET @SelTable = ' + '''' +  @TableName +  '''' + '
  SELECT
       tables.name AS TableName
      ,all_columns.name AS ColumnName
  
  FROM sys.all_columns
  INNER JOIN sys.tables ON sys.all_columns.object_id = sys.tables.object_id
  INNER JOIN sys.types ON sys.all_columns.user_type_id =                 
  sys.types.user_type_id 
  WHERE sys.tables.name = @SelTable
  ORDER BY all_columns.name'
  
  EXEC(@SQLCommand)
  </code></pre>
  
  <p>I would like to add a column that shows TableName.ColumnName, but the syntax defies me.  Any help would be greatly appreciated.
  Thanks in advance.</p>