0

I tried to do this:

SELECT SUM(SUBTOTAL as TODAYSALES) FROM dbo.SALESORD_HDR where ORDERDATE >=41187

But the browser throws an exception about the sum function saying 'SUM' is not a recognized built-in function name.

Any ideas?

3
  • if you are using something like PHP, this SQL should run on the server and never hit the front end HTML. and yes, it should be "SUM(SUBTOTAL) as TODAYSALES"
    – amphibient
    Oct 10, 2012 at 22:29
  • OK, sorry. I am using MS WebMatrix, CSHTML page with Razor syntax.
    – Bevan
    Oct 10, 2012 at 23:16
  • @DanGrossman - why the downvote? this was sucessfully answered by forum members as an error in syntax.
    – Bevan
    Oct 15, 2012 at 21:32

3 Answers 3

5

Doing a

SELECT SUM(SUBTOTAL) as TODAYSALES FROM ...

would work a lot better.

2

Your syntax seems off. It should be SELECT SUM(SUBTOTAL) AS TODAYSALES FROM dbo.SALESORD_HDR where ORDERDATE >= 41187

1
  • System.Collections.ObjectModel.ReadOnlyCollection`1[System.Object] is the result now.
    – Bevan
    Oct 10, 2012 at 23:17
1

Aliases must be defined outside the expression they are targeting:

SELECT SUM(SUBTOTAL) as TODAYSALES FROM dbo.SALESORD_HDR where ORDERDATE >=41187
1
  • sorry, yes i realise that now. the result is System.Collections.ObjectModel.ReadOnlyCollection`1[System.Object]
    – Bevan
    Oct 10, 2012 at 23:18

Not the answer you're looking for? Browse other questions tagged or ask your own question.