sql - Incorrect syntax near 'PIVOT' -
i'm running sql server 2008 r2. i'm trying build table takes data table structured this:
company | ded_id | descr 10 1 medins 10 2 life 10 3 pensn ... 10 50 domrel
and need build temp table out format this:
company | desc1 | desc2 | desc3 ... | desc50 10 medins life pensn domrel
so built following query:
select * ( select company,'desc'+cast(ded_id varchar(2)) dedid,descr deduction ) deds pivot (max(descr)for dedid in([desc1],[desc2],[desc3])) descs
so running gives following error:
msg 325, level 15, state 1, line 6 incorrect syntax near 'pivot'. may need set compatibility level of current database higher value enable feature. see set compatibility_level option of alter database.
i double checked compatibility level on database , set 100 can't issue. can think of other setting might causing behavior?
the possible reason type of issue imported database other source might running older version of sql server. anyway, have way out of it. follow steps below:
- right click on database (e.g. northwind).
- click 'properties'.
- click 'options', left pane, under 'select page' section.
- select appropriate database version per installation drop-down of 'compatibility level' @ right.
- save changes , try now.
below screenshot of properties window reference.
Comments
Post a Comment