-1
如何將行轉換爲列?如何將此列的行轉換爲列
CREATE TABLE [dbo].[Table_1]
(
[Bill_ID] [VARCHAR](20) NOT NULL,
[Customer_ID] [VARCHAR](20) NOT NULL,
[Bill_date] [DATE] NOT NULL,
[Bill_Amount] [VARCHAR](20) NOT NULL,
[Bill_Tax] [VARCHAR](20) NULL,
[Create_By] [VARCHAR](20) NOT NULL,
[Created_Date] [DATE] NOT NULL
)
ON [PRIMARY]
SELECT [Bill_ID],
[Customer_ID],
[Year],
[Bill_Amount],
[Bill_Tax],
[Create_By],
[Created_Date]
FROM (
SELECT [Bill_ID],
[Customer_ID],
Datename(month, CONVERT(DATE, [Bill_date])) AS 'Month Name',
Datename(year, CONVERT(DATE, '2016-03-14')) AS 'Year',
[Bill_Amount],
[Bill_Tax],
[Create_By],
[Created_Date]
FROM [Table_1]) AS table2 PIVOT(Sum([Bill_Amount]) FOR
(
SELECT datename(month, CONVERT(date, [Bill_date])) AS 'Month Name') IN (January, February, March, April, May, June, July, August, September, Octobor, November, December)))