English 中文(简体)
文件有日期列名称
原标题:File has date column names

我正在尝试导入一个文件, 该文件的日期是列名 。

例如:

  • Order Number
  • Total
  • jan2012
  • Feb2012

我想把它改成:

  • Order Number
  • Total
  • Date

因此,表格看起来如下:

OrderNumber    Total       Date 
1                5         Jan2012 
1                6         Feb2012 
2                3         Jan 2012 
2                4         Feb2012 

有什么建议吗?

问题回答

即称为PIVOT转换,有具体的任务做到这一点。

< a href=" "http://msdn.microsoft.com/en-us/library/ms177410%28v=sql. 105%29.aspx" rel="nofollow" > 这里 是 SQL 示例的链接( 如果你想了解它是如何运作的)

这里 是SSIS PIVOT转换

例如""http://sqlblog.com/blogs/eric_johnson/archive/2010/10/20/the-sis-pivot- transformation.aspx" rel="no follow" >这里

这种转换类型是 UNPIVOT :

select OrderNumber, Total, Date
from yourtable
unpivot
(
    date
    for col in (jan2012, Feb2012)
) unpiv

也可以使用 UNION All :

select ordernumber, total, jan2012 as date
from yourtable
union all
select ordernumber, total, feb2012 as date
from yourtable




相关问题
Export tables from SQL Server to be imported to Oracle 10g

I m trying to export some tables from SQL Server 2005 and then create those tables and populate them in Oracle. I have about 10 tables, varying from 4 columns up to 25. I m not using any constraints/...

SQL server: Can NT accounts be mapped to SQL server accounts

In our database we have an SQL server account that has the correct roles to access some of the databases. We are now switching to windows authentication and I was wondering if we can create a NT user ...

SQL Server 2000, ADO 2.8, VB6

How to determine if a Transaction is active i.e. before issuing Begin Transaction I want to ensure that no previous transaction are open.. the platform is VB6, MS-SQL Server 2000 and ADO 2.8

热门标签