我们的BA为我们提供了Excel表格,其中包含我在SQL表中加载的两列column1
和column2
。 column1
包含不同的值EmployeeID, FirstName, LastName, Address
,column2
包含受尊重的值。
如何将Column1
个不同的值转换为列,以便我的表格会以EmployeeID, FirstName, LastName, and Address
为列?
File
Column1 || Column2
EmployeeID || 00251
FirstName || Joe
LastName || Reed
Address || 101 5th Ave
EmployeeID || 00145
FirstName || Jen
LastName || Smith
Address || 1001 Henderson RD
我正在使用以下查询,但它发出错误。
SELECT pt.EmployeeID , pt.FirstName, pt.LastName, pt.[Address]
FROM
(
SELECT *
FROM FlatFile.UserList
) AS temp
PIVOT
(
MAX([COLUMN2])
FOR [COLUMNE1] IN ('EmployeeID','FirstName','LastName:','[Address]')
) as pt
错误:
Error Message:
Msg 102, Level 15, State 1, Line 11
Incorrect syntax near 'EmployeeID'.
答案 0 :(得分:2)