Marvin
Marvin

Reputation: 569

Sql FOR XML PATH returns Incorrect Syntax near 'PATH'

This seems like this should be really simple, but I don't see what's wrong.

DECLARE @companies TABLE(
    [companyId] SMALLINT        
)

INSERT INTO @companies
   SELECT TOP 3 tc.CompanyID AS 'companyId'
   FROM dbo.tblCompanies tc

SELECT * 
FROM @companies c

This query returns this data.

companyId
---------
  1
  2
  3

When I try to use FOR XML, these work:

-- this works
SELECT  companyId
FROM @companies [company]
FOR XML AUTO

-- this works
SELECT  companyId
FROM @companies [company]
FOR XML RAW

But this returns an error

Incorrect syntax near 'PATH'

and I can't figure out why.

-- why doesn't this work?
SELECT companyId
FROM @companies
FOR XML PATH('company')

What am I missing?

Upvotes: 1

Views: 1976

Answers (1)

Marvin
Marvin

Reputation: 569

Geez, I was connecting to a server at work that was Sql Server 2000. That's why it wasn't working. Wasn't supported.

Upvotes: 2

Related Questions