由买买提看人间百态

topics

全部话题 - 话题: pivotdata
(共0页)
z**********8
发帖数: 2049
1
WITH PivotData AS
(
select CalendarYear, state, personid
from [dbo].[tblImportPerson])
select CalendarYear, [2008], [2009]
from pivotData
pivot ( sum(personid) for state IN ([2008],[2009])) as p;
--Msg 102, Level 15, State 1, Line 9
Incorrect syntax near ')'.
谢谢!
z**********8
发帖数: 2049
2
我所有的数据都varchar, 也不行啊。
with pivotdata as
(
select state, year, personid
from [dbo].[Sheet2$]
)
select state, [2008], [2009]
from pivotdata
pivot(count(personid) FOR year in ([2008], [2009])) as p;
(共0页)