Please start any new threads on our new site at https://forums.sqlteam.com. We've got lots of great SQL Server experts to answer whatever question you can come up with.

 All Forums
 SQL Server 2005 Forums
 Transact-SQL (2005)
 Can't Figure out this PIVIOT statment

Author  Topic 

thedryden
Starting Member

23 Posts

Posted - 2008-02-08 : 11:07:44
There is something wrong with this PIVOT statment and I can't figgure out what. It just keeps telling me that: "Incorrect syntax near '<FILE 12>'."

Can anyone help!

SELECT USER_ID
, CUID
, FULL_NAME
, SUBJECT
, HAS_SUBJECT
FROM (
SELECT u.USER_ID
, u.CUID
, u.FULL_NAME
, r.SUBJECT
, 1 AS HAS_SUBJECT
FROM CTS.dbo.EMAIL_RECIPIENTS u
INNER JOIN CTS.dbo.EMAIL_DISTRO d ON u.USER_ID=d.USER_ID
INNER JOIN CTS.dbo.EMAIL r ON d.EMAIL_ID=r.EMAIL_ID
) t
PIVOT ( SUM(HAS_SUBJECT) FOR SUBJECT IN ( '<FILE 12>','<FILE 5>','Monthly NCR Volume Reports','Updates to the NDC Scorecard','Weekly NCR Volume Reports' ) ) AS PA

jdaman
Constraint Violating Yak Guru

354 Posts

Posted - 2008-02-08 : 11:40:09
Try wrapping your list of SUBJECTs in brackets [] instead of single quotes.
Go to Top of Page

thedryden
Starting Member

23 Posts

Posted - 2008-02-08 : 14:31:34
That fixed it thanks!
Go to Top of Page
   

- Advertisement -