Microsoft SQL Server
 
Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
 
 
User Name:
Password:
Remember me
Go Back   ASP Free ForumsDatabaseMicrosoft SQL Server

Reply
Add This Thread To:
  Del.icio.us   Digg   Google   Spurl   Blink   Furl   Simpy   Y! MyWeb 
Thread Tools Search this Thread Rate Thread Display Modes
 
Unread ASP Free Forums Sponsor:
  #1  
Old December 29th, 2004, 04:08 AM
shruthi_pqr shruthi_pqr is offline
Contributing User
ASP Free Newbie (0 - 499 posts)
 
Join Date: Mar 2004
Posts: 30 shruthi_pqr User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 2 h 52 m 30 sec
Reputation Power: 5
Help Select Query

i have the table with the following structure and data

Values
1
2
3
4
5

so i want a query to this follows output

Values SumVal
1 1
2 3
3 6
4 10
5 15

Reply With Quote
  #2  
Old December 29th, 2004, 06:10 PM
lewy's Avatar
lewy lewy is offline
Alter Ego Wizard
ASP Free Specialist (4000 - 4499 posts)
 
Join Date: Jun 2004
Location: Edinburg Tx
Posts: 4,376 lewy User rank is General 6th Grade (Above 100000 Reputation Level)lewy User rank is General 6th Grade (Above 100000 Reputation Level)lewy User rank is General 6th Grade (Above 100000 Reputation Level)lewy User rank is General 6th Grade (Above 100000 Reputation Level)lewy User rank is General 6th Grade (Above 100000 Reputation Level)lewy User rank is General 6th Grade (Above 100000 Reputation Level)lewy User rank is General 6th Grade (Above 100000 Reputation Level)lewy User rank is General 6th Grade (Above 100000 Reputation Level)lewy User rank is General 6th Grade (Above 100000 Reputation Level)lewy User rank is General 6th Grade (Above 100000 Reputation Level)lewy User rank is General 6th Grade (Above 100000 Reputation Level)lewy User rank is General 6th Grade (Above 100000 Reputation Level)lewy User rank is General 6th Grade (Above 100000 Reputation Level)lewy User rank is General 6th Grade (Above 100000 Reputation Level)lewy User rank is General 6th Grade (Above 100000 Reputation Level)lewy User rank is General 6th Grade (Above 100000 Reputation Level)  Folding Points: 1009 Folding Title: Novice Folder
Time spent in forums: 1 Month 1 Week 1 Day 21 h 21 m 31 sec
Reputation Power: 1391
What exactly is the second colum of what you want to do? Is it a count of How many? Or does it add all the 1's , all the 2's etc. You need to be more specific.

Reply With Quote
  #3  
Old December 29th, 2004, 09:16 PM
Memnoch's Avatar
Memnoch Memnoch is offline
Unholy Moderator
ASP Free God 14th Plane (11500 - 11999 posts)
 
Join Date: Oct 2003
Location: In hell, where did you think?
Posts: 11,760 Memnoch User rank is Lieutenant Colonel (40000 - 50000 Reputation Level)Memnoch User rank is Lieutenant Colonel (40000 - 50000 Reputation Level)Memnoch User rank is Lieutenant Colonel (40000 - 50000 Reputation Level)Memnoch User rank is Lieutenant Colonel (40000 - 50000 Reputation Level)Memnoch User rank is Lieutenant Colonel (40000 - 50000 Reputation Level)Memnoch User rank is Lieutenant Colonel (40000 - 50000 Reputation Level)Memnoch User rank is Lieutenant Colonel (40000 - 50000 Reputation Level)Memnoch User rank is Lieutenant Colonel (40000 - 50000 Reputation Level)Memnoch User rank is Lieutenant Colonel (40000 - 50000 Reputation Level)Memnoch User rank is Lieutenant Colonel (40000 - 50000 Reputation Level)Memnoch User rank is Lieutenant Colonel (40000 - 50000 Reputation Level) 
Time spent in forums: 3 Weeks 5 Days 5 h 22 m 16 sec
Reputation Power: 443
Where's the
1
3
6
10
15
coming from???

Reply With Quote
  #4  
Old December 29th, 2004, 11:12 PM
shruthi_pqr shruthi_pqr is offline
Contributing User
ASP Free Newbie (0 - 499 posts)
 
Join Date: Mar 2004
Posts: 30 shruthi_pqr User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 2 h 52 m 30 sec
Reputation Power: 5
with more specific

Quote:
Originally Posted by lewy
What exactly is the second colum of what you want to do? Is it a count of How many? Or does it add all the 1's , all the 2's etc. You need to be more specific.

The second column value is
when first value of first coloum is selected the sumvalue should be 1
when second value of first column is selected(2) the sumvalue should be sum of selected(2) value and the sum of previous value(1) ie

value sumvalue
1 1
2 3

when third value of first column is selected(3) the sumvalue should be sum of selected(3) value and the sum of previous values(1+2) ie 3+1+2=6

when third value of first column is selected(4) the sumvalue should be sum of selected(4) value and the sum of previous values(1+2+3) ie 4+1+2+3=10
and so on

Reply With Quote
  #5  
Old December 30th, 2004, 07:50 AM
Dumbo Dumbo is offline
Registered User
ASP Free Newbie (0 - 499 posts)
 
Join Date: Dec 2004
Posts: 29 Dumbo User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 4 h 27 m 31 sec
Reputation Power: 0
This will do the trick

declare @i integer
set @i=1
create table #test (col1 integer,col2 integer)
while @i<10
begin
insert into #test (col1) values (@i)
set @i=@i+1
end
update #test set col2=(select sum(col1) from #test a where a.col1<=#test.col1)
select * from #test
drop table #test

Reply With Quote
Reply

Viewing: ASP Free ForumsDatabaseMicrosoft SQL Server > Help Select Query


Thread Tools  Search this Thread 
Search this Thread:

Advanced Search
Display Modes  Rate This Thread 
Rate This Thread:


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
View Your Warnings | New Posts | Latest News | Latest Threads | Shoutbox
Forum Jump


Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
  
 





© 2003-2008 by Developer Shed. All rights reserved. DS Cluster 2 hosted by Hostway