Question

I'm using OPENQUERY on SQL Server 2008, I have this query:

SELECT * 
FROM OPENQUERY(MyLinkedServer, 'SELECT familyCode, sum(member) FROM customers')

I get this error:

Column familyCode or expression in SELECT list not valid

When I run the code without SUM, it works perfectly:

SELECT * 
FROM OPENQUERY(MyLinkedServer, 'SELECT familyCode, member FROM customers')

What's the correct syntax for including the SUM function?

Thank you!

Was it helpful?

Solution

you need a group by clause when using an aggregation function like SUM

SELECT familyCode, sum(member) FROM customers group by familyCode
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top