rosebrit3
rosebrit3

Reputation: 523

Data export from SQL Server to Excel

I have been thinking of a way to export data from SQL to Excel. There is the option of making use of export/import wizard. Bit in my case, the table has columns, which consists of numbers. And these numbers refer to values which are stored in another table. For example, suppose the table has a column country_id with numbers 1, 2,3 and so on. There is another table which consists of these numbers as its primary key and its corresponding row, the country name.

Eg:

1 UK

2 China

3 USA

So, on exporting i want these country names to appear instead of the numbers. This will require a customized query. Can anyone please provide me with an example on how to start this? How to write the export part of the query? Are there any tutorials on how to write these type of queries.

Upvotes: 0

Views: 1352

Answers (1)

Marcel N.
Marcel N.

Reputation: 13986

You can still use the import/export wizard and select option 2 in the wizard step Specify Table Copy or Query. Meaning:

enter image description here

You can use a query like this. Since I don't know your table names,let's call the first table ChildTable (the one with the FK) and the second table, the one with country names, CountryTable.

SELECT A.Col1, A.Col2, B.Country_Name,
FROM dbo.ChildTable A
INNER JOIN dbo.CountryTable B
  ON B.Id = A.Country_Id

Upvotes: 4

Related Questions