简体   繁体   English

在SQL中将数据从一个表导出到另一个表

[英]Exporting data from one table to another in SQL

This is what I am working with: 这就是我正在使用的:

Select fields 1-24 dbo.tablename where multiple !=2;

However, in the original table, tablename, some fields are titled differently. 但是,在原始表表名中,某些字段的标题不同。 This is a work in progress so pardon some of the inefficiencies. 这是一项正在进行的工作,因此请原谅一些低效率的地方。 One example is the 6th column/field, which is titled xacct in tablename, but titled xaccount in result. 一个示例是第六列/字段,在表名中标题为xacct,在结果中标题为xaccount。

In short: Can one set up a command such as above and still account for differing field names all the while leaving the data and it's type unchanged? 简而言之:在设置数据类型不变的同时,是否可以设置上述命令并始终解决不同的字段名称?

if you are doing an insert/select, column names are irrelevant, only order is important. 如果要执行插入/选择,则列名无关紧要,仅顺序很重要。 If you are trying to rename the columns in a select statement, use the standard SQL: 如果要重命名select语句中的列,请使用标准SQL:

SELECT field1 AS column1
     , field2 AS column2
     , field3 AS column3
     , multiple AS multiply
  FROM dbo.tablename
 WHERE multiple != 2;

Where 'FIELD1' is original column name, 'COLUMN1' is new name you are providing. 其中“ FIELD1”是原始列名,“ COLUMN1”是提供的新名称。

You don't have to specify new names for all of the columns, only those you are changing: 您不必为所有列指定新名称,只需为要更改的名称指定:

SELECT field1 AS tedd_e_bear
     , field2           
     , field3 AS spin_fidget
     , multiple AS multiply
  FROM dbo.tablename
 WHERE multiple != 2;

In the above example, field 2 still has the name field2. 在上面的示例中,字段2仍具有名称field2。

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

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