Solved

# The SUM function requires 1 arguments.

Posted on 2005-04-11
2,640 Views
This works fine, but the resulting value is w/out commas to the left of the decimal:  315683437.1000

SELECT SUM(LastFillQuantity*CAST(LastFillPrice AS Money)) AS 'Total \$ - '
where timeofexecution  >= left(getdate()-0, 11)
and destination = 'aaaa'

I usually do a conversion w/MONEY in order to get the commas in place -- like this query gives me this:
Stocks Volume -   232,096,074

SELECT 'Stocks Volume -   '+LTRIM(LEFT(CONVERT(char(16),CAST(SUM(LastFillQuantity) AS MONEY),1),13)),
+'Total # Trades - '+LTRIM(LEFT(CONVERT(char(16),CAST(count(*) AS MONEY),1),13))

but when i try that here, i get this:
Server: Msg 174, Level 15, State 1, Line 1
The SUM function requires 1 arguments.

SELECT CONVERT(varchar(15),CAST(SUM(LastFillQuantity*CAST(LastFillPrice AS Money),1) AS 'Total \$ - '
where timeofexecution  >= left(getdate()-0, 11)
and destination = 'aaaa'

any help?
0
Question by:RLLewis

LVL 17

Expert Comment

Maybe this

SELECT CONVERT(varchar(15),SUM(LastFillQuantity*CAST(LastFillPrice AS Money))) AS 'Total \$ - '
where timeofexecution  >= left(getdate()-0, 11)
and destination = 'aaaa'

0

LVL 1

Author Comment

no, that gives me this value:  315683437.10

i've always gotten my commas in place w/my money conversion.  it's just not happening this time, though
0

LVL 17

Accepted Solution

I've got it

SELECT CONVERT(varchar(15),SUM(LastFillQuantity*CAST(LastFillPrice AS Money)),1) AS 'Total \$ - '
where timeofexecution  >= left(getdate()-0, 11)
and destination = 'aaaa'
0

LVL 1

Author Comment

Beauty!  I've been bothering over these two items for much of the afternoon.  Sometimes it's these little ones that will get ya.  I can't thank you enough.
0

LVL 17

Expert Comment

0

## Featured Post

This is my first ever Article on EE or elsewhere; therefore, please bear with me if I have some discrepancies in my writing. I read many articles and questions related to "how to pass values to SSIS packages at run-time?"  Hence, this common ques…
I wrote this interesting script that really help me find jobs or procedures when working in a huge environment. I could I have written it as a Procedure but then I would have to have it on each machine or have a link to a server-related search that …
Familiarize people with the process of utilizing SQL Server functions from within Microsoft Access. Microsoft Access is a very powerful client/server development tool. One of the SQL Server objects that you can interact with from within Microsoft Ac…
Viewers will learn how to use the UPDATE and DELETE statements to change or remove existing data from their tables. Make a table: Update a specific column given a specific row using the UPDATE statement: Remove a set of values using the DELETE s…