{"id":200,"date":"2012-05-14T05:32:31","date_gmt":"2012-05-14T05:32:31","guid":{"rendered":"https:\/\/sqlserverlearner.azurewebsites.net\/2012\/05\/14\/duplicate-column-names-are-not-allowed-in-result-sets-obtained-through-openquery-and-openrowset-the-column-name-a-is-a-duplicate\/"},"modified":"2012-05-14T05:32:31","modified_gmt":"2012-05-14T05:32:31","slug":"duplicate-column-names-are-not-allowed-in-result-sets-obtained-through-openquery-and-openrowset-the-column-name-a-is-a-duplicate","status":"publish","type":"post","link":"https:\/\/sqlserverlearner.com\/2012\/05\/14\/duplicate-column-names-are-not-allowed-in-result-sets-obtained-through-openquery-and-openrowset-the-column-name-a-is-a-duplicate\/","title":{"rendered":"Duplicate column names are not allowed in result sets obtained through OPENQUERY and OPENROWSET. The column name “A” is a duplicate."},"content":{"rendered":"

Error:<\/strong>
\n
\nMsg 492, Level 16, State 1, Line 3
\nDuplicate column names are not allowed in result sets obtained through OPENQUERY and OPENROWSET. The column name “A” is a duplicate.
\n<\/font>
\nPossible Reason:<\/strong>
\nColumn names being duplicate in the result set returned by OPENQUERY (or) OPENROWSET.<\/p>\n

Example:
\n[sql]
\nSELECT 1 AS A,2 AS A
\n[\/sql]
\nExecutes Successfully!!!<\/p>\n

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

Errors Out with Msg 492, Level 16, State 1, Line 3.<\/p>\n

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

appropriate to SQL Server 2005,SQL Server 2008,SQL Server 2008 r2,SQL Server 2012<\/p>\n","protected":false},"excerpt":{"rendered":"

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…<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[128,41],"tags":[1931],"_links":{"self":[{"href":"https:\/\/sqlserverlearner.com\/wp-json\/wp\/v2\/posts\/200"}],"collection":[{"href":"https:\/\/sqlserverlearner.com\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/sqlserverlearner.com\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/sqlserverlearner.com\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/sqlserverlearner.com\/wp-json\/wp\/v2\/comments?post=200"}],"version-history":[{"count":0,"href":"https:\/\/sqlserverlearner.com\/wp-json\/wp\/v2\/posts\/200\/revisions"}],"wp:attachment":[{"href":"https:\/\/sqlserverlearner.com\/wp-json\/wp\/v2\/media?parent=200"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/sqlserverlearner.com\/wp-json\/wp\/v2\/categories?post=200"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/sqlserverlearner.com\/wp-json\/wp\/v2\/tags?post=200"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}