简体   繁体   English

数据从SQL Server导出到Excel

[英]Data export from SQL Server to Excel

I have been thinking of a way to export data from SQL to Excel. 我一直在想将数据从SQL导出到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. 例如,假设该表的country_id列的编号为1,2,3,依此类推。 There is another table which consists of these numbers as its primary key and its corresponding row, the country name. 还有另一个表,其中包含这些数字作为其主键以及其对应的行(国家/地区名称)。

Eg: 例如:

1 UK 1英国

2 China 2中国

3 USA 3美国

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 . 您仍然可以使用导入/导出向导,并在向导步骤“ Specify Table Copy or Query选择选项2。 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. 由于我不知道您的表名,因此我们将第一个表称为ChildTable(带FK的表),将第二个表称为国家/地区名称CountryTable。

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

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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