Unix Technical Forum

sum with increment

This is a discussion on sum with increment within the SQL Server forums, part of the Microsoft SQL Server category; --> TO all I have tabel autonumber value 1 1 2 5 3 6 4 8 5 9 6 10 ...


Go Back   Unix Technical Forum > Database Server Software > Microsoft SQL Server > SQL Server

FAQ Members List Calendar Search Today's Posts Mark Forums Read
  #1 (permalink)  
Old 02-29-2008, 07:37 PM
cahyadi
 
Posts: n/a
Default sum with increment

TO all
I have tabel
autonumber value
1 1
2 5
3 6
4 8
5 9
6 10
7 12
8 13
9 8
10 10
and if i want sum with increment 2
autonumber value
1 - 2 1 + 5 = 6
3 - 4 6 + 8 = 14
5 - 6 19
7 - 8 25
9 - 10 18

please help.............. trims

Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
  #2 (permalink)  
Old 02-29-2008, 07:38 PM
David Portas
 
Posts: n/a
Default Re: sum with increment

cahyadi wrote:
> TO all
> I have tabel
> autonumber value
> 1 1
> 2 5
> 3 6
> 4 8
> 5 9
> 6 10
> 7 12
> 8 13
> 9 8
> 10 10
> and if i want sum with increment 2
> autonumber value
> 1 - 2 1 + 5 = 6
> 3 - 4 6 + 8 = 14
> 5 - 6 19
> 7 - 8 25
> 9 - 10 18
>
> please help.............. trims


If "autonumber" really means an IDENTITY column then this looks like a
very silly and impractical design. What exactly is this data supposed
to represent?

Apparently you want to sum pairs of rows:

SELECT A.autonumber, B.autonumber
A.value+B.value AS tot
FROM tbl AS A
LEFT JOIN tbl AS B
ON A.autonumber + 1 = B.autonumber
WHERE A.autonumber IN (1,3,5,7,9) ;

(untested)

The problem is that you can't prevent gaps in the sequence of values in
an auto-numbered IDENTITY column. So there is no guarantee that each
row will have a "next" row.

--
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/m...S,SQL.90).aspx
--

Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
  #3 (permalink)  
Old 02-29-2008, 07:38 PM
Doug
 
Posts: n/a
Default Re: sum with increment

What class are you taking that this is homework for????

Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
  #4 (permalink)  
Old 02-29-2008, 07:39 PM
cahyadi
 
Posts: n/a
Default Re: sum with increment

thanks for your information, but if i want increment 7 i try syntax :
SELECT A.autobaris, B.autobaris AS Expr1, A.nilai + B.nilai AS tot
FROM ac A LEFT OUTER JOIN
ac B ON A.autobaris + 4 = B.autobaris
and the result :
autobaris exp1 tot
1 4 9
5 8 22
9 null null
but i want the result :
autobaris exp1 tot
1 4 20
5 8 44
9 10 18
please help thanks

Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
  #5 (permalink)  
Old 02-29-2008, 07:39 PM
MC
 
Posts: n/a
Default Re: sum with increment

Ummm, why A.autobaris + 4 if you want an increment of 7? shouldnt you
specify A.autobaris + 6?


MC


"cahyadi" <csastra99@gmail.com> wrote in message
news:1141867886.185553.79400@p10g2000cwp.googlegro ups.com...
> thanks for your information, but if i want increment 7 i try syntax :
> SELECT A.autobaris, B.autobaris AS Expr1, A.nilai + B.nilai AS tot
> FROM ac A LEFT OUTER JOIN
> ac B ON A.autobaris + 4 = B.autobaris
> and the result :
> autobaris exp1 tot
> 1 4 9
> 5 8 22
> 9 null null
> but i want the result :
> autobaris exp1 tot
> 1 4 20
> 5 8 44
> 9 10 18
> please help thanks
>



Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
  #6 (permalink)  
Old 02-29-2008, 07:39 PM
cahyadi
 
Posts: n/a
Default Re: sum with increment

that is sample......
in my aplikasi autobaris is date of transaction. and in my aplication
increment is dinamis. thanks.
sory for my english..

Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
Reply


Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On
Forum Jump


All times are GMT. The time now is 03:32 PM.


Powered by vBulletin® Version 3.6.5
Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
SEO by vBSEO 3.2.0
www.UnixAdminTalk.com