0

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.

rosebrit3
  • 523
  • 1
  • 18
  • 32
  • Can you write a query that returns the data you want to export? – Greg Jun 29 '12 at 19:08
  • possible duplicate of [How do you transfer or export SQL Server 2005 data to Excel](http://stackoverflow.com/questions/87735/how-do-you-transfer-or-export-sql-server-2005-data-to-excel) – Ken White Jun 29 '12 at 19:09
  • This is the query that i have written based on the answer by Coon. SELECT A.FirstName, A.LastName, B.Name FROM LMS_UserInfo AS A INNER JOIN LMS_HierarchyMember AS B ON B.HierarchyMemberID = A.HierachyMemberID. Now, can anyone give me a start with writing the export procedure, please:) – rosebrit3 Jul 03 '12 at 08:12

1 Answers1

4

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
Marcel N.
  • 13,726
  • 5
  • 47
  • 72