简体   繁体   中英

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.

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

在此处输入图片说明

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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM