title: How to remove/rename a duplicate column in SQL (not duplicate rows)
body: <p>When attempting to do an OPENQUERY from Sybase to Microsoft SQL I run into an error:</p>
  
  <blockquote>
    <p>Duplicate column names are not allowed in result sets obtained through
    OPENQUERY and OPENROWSET. The column name "PatientID" is a duplicate.</p>
  </blockquote>
  
  <p>The query I have built joins 2 tables based on similar admissionID and patientID.</p>
  
  <p>For Instance:</p>
  
  <pre><code>PatID   AdmID   Loc  PatID  AdmID   Doctor 
  1         5      NC    1      5      Smith 
  2         7      SC    2      7      Johnson
  </code></pre>
  
  <p>The real query of course has a ton more information than just this.</p>
  
  <p>Is there a good way to rename or remove one of the AdmID and PatID columns?</p>
  
  <p>I attempted:</p>
  
  <pre><code>SELECT * INTO #tempTable
  ALTER #tempTable
  DROP COLUMN PatID
  </code></pre>
  
  <p>This does not work since PatID is ambiguous.</p>
  
  <p>I also attempted:</p>
  
  <pre><code>SELECT firstTable.PatID as 'pID', * FROM...
  </code></pre>
  
  <p>This does not work either.</p>