Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Unhelpful error message when doing pivot

When I write the following query:

SELECT id,status
FROM dbo.View_Request
PIVOT ( COUNT(id) FOR status IN([CL],[HOLD])) AS pvt

I get a vague error message:

Msg 102, Level 15, State 1, Line 3
Incorrect syntax near '('.

What exactly am I doing wrong?

like image 244
jsmith Avatar asked Mar 27 '26 11:03

jsmith


1 Answers

Your database is presumably at SQL Server 2000 compatibility level. You need to fix that then you will get these other error messages instead.

Msg 207, Level 16, State 1, Line 5
Invalid column name 'id'.
Msg 207, Level 16, State 1, Line 5
Invalid column name 'status'.

The only columns you will have available to use in the SELECT list are CL and HOLD

like image 71
Martin Smith Avatar answered Mar 29 '26 05:03

Martin Smith



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!