Today help people make a cross watch and find a strange problem
Select REGION,POST_CITY,COMPANYID,COMPANYNAME,[HP Supplies assured store] as [HP stores],[HP products store] as [HP Product store],[Branch (branch)] as [branch office ( Branch)] From
(
Select
C.region,c.post_city,a.companyid,a.companyname,b.itemid,b.storetype
From
Profiling_company A
Left join Profiling_branch B on A.companyid=b.companyid
INNER JOIN dbo. Rebate_partner C on a.companyid=c.company_id
where a.active=1
and c.region= ' North '
--and post_city= ' Qinhuangdao '
) as PB
PIVOT
(
Count (ItemId) for Storetype in ([HP consumable store],[HP product store],[Branch (branch)])
) as PVT
The above statement did not make an error, but the total error "' PIVOT ' has syntax errors near it." You may want to enable this feature by setting the compatibility level of the current database to a higher value.
A preliminary guess is that there is no new syntax to support 2005, pivot keywords are not supported, (note: This library was given to me by someone, maybe from 2000)
As prompted, you need to modify the compatibility level of the database you are manipulating, searching the web for a system stored procedure to do this
EXEC sp_dbcmptlevel kingdee,90
Where ' Kingdee ' is you want to modify the compatibility of the database name, after running, rerun the above SQL statement, executed successfully
This article from Csdn Blog, reproduced please indicate the source: http://blog.csdn.net/lee576/archive/2008/01/17/2048565.aspx