Database compatibility level error, total error "' PIVOT ' near syntax error

Source: Internet
Author: User

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

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.