Duplicate column names are not allowed in result sets obtained through OPENQUERY and OPENROWSET. The column name “A” is a duplicate.

Error:

Msg 492, Level 16, State 1, Line 3
Duplicate column names are not allowed in result sets obtained through OPENQUERY and OPENROWSET. The column name “A” is a duplicate.

Possible Reason:
Column names being duplicate in the result set returned by OPENQUERY (or) OPENROWSET.

Example:
[sql]
SELECT 1 AS A,2 AS A
[/sql]
Executes Successfully!!!

When the same query is used in the OPENROWSET.
[sql]
SELECT * FROM OPENROWSET(‘SQLOLEDB’,
‘Server=(local);Trusted_Connection=Yes;Database=Master’,
‘SELECT 1 AS A,2 AS A’)
[/sql]

Errors Out with Msg 492, Level 16, State 1, Line 3.

Fix/Resolution:
Make sure that each and every column in the result set returned by OPENQUERY (or) OPENROWSET has a different name.
[sql]
SELECT * FROM OPENROWSET(‘SQLOLEDB’,
‘Server=(local);Trusted_Connection=Yes;Database=Master’,
‘SELECT 1 AS A,2 AS B’)
[/sql]

appropriate to SQL Server 2005,SQL Server 2008,SQL Server 2008 r2,SQL Server 2012