Home All Groups Group Topic Archive Search About
Author
22 Jun 2006 10:29 PM
brownjenkn
I have what is probably a simple problem and I guess I'm just looking
for whatever solutions you all can suggest...

I have this query:

Select columnA , sum(columnB) as VAL from myTable where
columnA in ('01,'02') group by columnA

which may return:

columnA    VAL
-------------   ---------
01    100.00
02    200.00

Just using SQL, I'd like to return a table that looks like:

columnA   VAL
-------------   ---------
01    300.00


and I don't want to use the query:

Select '01', sum(columnB) as VAL from myTable where
columnA in ('01','02')

Any suggestions?  Your help is much appreciated.

Marc

Author
22 Jun 2006 10:37 PM
David Portas
brownje***@aol.com wrote:
Show quote
> I have what is probably a simple problem and I guess I'm just looking
> for whatever solutions you all can suggest...
>
> I have this query:
>
> Select columnA , sum(columnB) as VAL from myTable where
> columnA in ('01,'02') group by columnA
>
> which may return:
>
> columnA    VAL
> -------------   ---------
> 01    100.00
> 02    200.00
>
> Just using SQL, I'd like to return a table that looks like:
>
> columnA   VAL
> -------------   ---------
> 01    300.00
>
>
> and I don't want to use the query:
>
> Select '01', sum(columnB) as VAL from myTable where
> columnA in ('01','02')
>
> Any suggestions?  Your help is much appreciated.
>
> Marc

Maybe like this:

SELECT MIN(columnA) AS columnA, SUM(columnB) AS val
FROM myTable
WHERE columnA IN ('01','02');

--
David Portas, SQL Server MVP

Whenever possible please post enough code to reproduce your problem.
Including CREATE TABLE and INSERT statements usually helps.
State what version of SQL Server you are using and specify the content
of any error messages.

SQL Server Books Online:
http://msdn2.microsoft.com/library/ms130214(en-US,SQL.90).aspx
--

AddThis Social Bookmark Button