-1

I have one scenario in which I am getting a lot of employee data like address, qualification, work experience, etc from different tables into a new table.

In the required result set there are a few columns which have same(duplicate) name.
For example the address column appears multiple times. In my new table I have these column names saved as Address1, Address2, etc and while using select command I am using alias to rename the result set from address1 or address2 to address.

I would like to export this data using SQL server Import Export Wizard but the problem is that SQL won't let me export the result set with duplicate column names(since I have fetched the results using same alias for multiple columns).

The Error I get is

Could not connect source component. Error 0xc0207015

  • You lost me there at the end. You have a select statement, you understand how to provide an alias for the columns - why is that not working with the Import/Export wizard? – billinkc Oct 11 '17 at 13:52
  • I am able to get the results with select statement. While exporting the result set, my statements gets successfully parsed too. I am able to view the preview too. Just dont know whats stopping it from getting exported. And thank you for the revert. – Vashisht Varun Oct 11 '17 at 13:53
  • Don't apologize for first posts. It's redundant. It's not part of the issue and comments will help direct to missing information or any SO FAQs to read if needed. – Nope Oct 11 '17 at 14:12

1 Answers1

0

I'm not sure what you're doing wrong, but you can alias columns just fine in the import/export wizard.

In my source selection, I was given the choice between tables and Query, I selected Query and used the following query.

SELECT
    P.Address AS Address1
,   P.Person
,   A.Address AS Address2
,   A.City
FROM (SELECT 1 AS Address, 2 AS Person) P 
    CROSS APPLY(SELECT 1 AS Address, 3 AS City) AS A

enter image description here

I chose to export to flat file and my resulting file looked like

Address1,Person,Address2,City
1,2,1,3
billinkc
  • 59,250
  • 9
  • 102
  • 159