Hi!
This is probably simple (or impossible) but I can't figure out how to add to
values into 1 in a result.
Something like this:
select
sum( lala ) as sum_1,
sum( lele ) as sum_2,
add( sum_1 + sum_2) as sum_tot
from myTable
I could ofcourse use lala and lele in a new sum statement, but both can be
quite complicated statements and I thought there might be an easier way
around?
Regards,
PeterSELECT sum_1,
sum_2,
sum_1+sum_2 As sum_tot
FROM
(SELECT sum(lala) as sum_1,
sum (lele) as sum_2
FROM mytable ) X
"Peter Hartln" <peter@.data.se> wrote in message
news:ugHGLt$JGHA.2828@.TK2MSFTNGP12.phx.gbl...
> Hi!
> This is probably simple (or impossible) but I can't figure out how to add
> to values into 1 in a result.
> Something like this:
> select
> sum( lala ) as sum_1,
> sum( lele ) as sum_2,
> add( sum_1 + sum_2) as sum_tot
> from myTable
> I could ofcourse use lala and lele in a new sum statement, but both can be
> quite complicated statements and I thought there might be an easier way
> around?
> Regards,
> Peter
>
>|||Hi
CREATE TABLE Test
(
col1 INT,
col2 INT
)
INSERT INTO Test VALUES (1,5)
INSERT INTO Test VALUES (20,30)
CREATE FUNCTION dbo.calc_sum
(
@.arg1 AS int,
@.arg2 AS int
)
RETURNS int
AS
BEGIN
RETURN (SELECT @.arg1+@.arg2)
END
GO
SELECT SUM(col1),SUM(col2),dbo.calc_sum(SUM(col1),SUM(col2))
FROM Test
"Peter Hartln" <peter@.data.se> wrote in message
news:ugHGLt$JGHA.2828@.TK2MSFTNGP12.phx.gbl...
> Hi!
> This is probably simple (or impossible) but I can't figure out how to add
> to values into 1 in a result.
> Something like this:
> select
> sum( lala ) as sum_1,
> sum( lele ) as sum_2,
> add( sum_1 + sum_2) as sum_tot
> from myTable
> I could ofcourse use lala and lele in a new sum statement, but both can be
> quite complicated statements and I thought there might be an easier way
> around?
> Regards,
> Peter
>
>|||"Peter Hartln" <peter@.data.se> wrote in message
news:ugHGLt$JGHA.2828@.TK2MSFTNGP12.phx.gbl...
> Hi!
> This is probably simple (or impossible) but I can't figure out how to add
> to values into 1 in a result.
> Something like this:
> select
> sum( lala ) as sum_1,
> sum( lele ) as sum_2,
> add( sum_1 + sum_2) as sum_tot
> from myTable
> I could ofcourse use lala and lele in a new sum statement, but both can be
> quite complicated statements and I thought there might be an easier way
> around?
> Regards,
> Pete
The easiest way would be to do the addition in the client application.
Otherwise, no, you have to repeat the SUMs.|||Try this
SELECT sum_lala, sum_lele, sum_lala + sum_lele AS sum_lala_lele
FROM (SELECT SUM(lala) AS sum_lala, SUM(lele) AS sum_lele
FROM andys_test_table) summary
No comments:
Post a Comment