Site Sponsored By: SQLDSC - SQL Server Desired State Configuration
Please start any new threads on our new
site at https://forums.sqlteam.com. We've got lots of great SQL Server
experts to answer whatever question you can come up with.
hi allvery new to sqli have one table, with 7 fieldsreg_no name, tickets, date,i need to sum the ticketsbut when the sum reaches 250 i need to select the people in those records and email them. any ideas how to do this. help need badlythanks for any help in advanceregardsdeeomen
Sachin.Nand
2937 Posts
Posted - 2010-06-04 : 05:52:16
Sum for each person or the whole sum.Please post some sample output.PBUH
madhivanan
Premature Yak Congratulator
22864 Posts
Posted - 2010-06-04 : 06:00:24
It seems OP meant running sumMadhivananFailing to plan is Planning to fail
Deeomen
Starting Member
3 Posts
Posted - 2010-06-04 : 06:02:38
hii needreg_no name, email, contact_no, tickets_required1 dee dfs 23 52 john dsf 24234 4need to sum tickets requireds but when the sum hits 250 i need all the records that make up the 250
Sachin.Nand
2937 Posts
Posted - 2010-06-04 : 06:16:17
I still dont get it.What do you mean "all the records that make up 250"?If I it guess right the there will be repepeating records for each name.PBUH
webfred
Master Smack Fu Yak Hacker
8781 Posts
Posted - 2010-06-04 : 06:18:48
We need table structure, sample data and wanted output as always...No, you're never too old to Yak'n'Roll if you're too young to die.
Deeomen
Starting Member
3 Posts
Posted - 2010-06-04 : 06:26:12
tableRegistration_no int Name varchar(MAX) Department varchar(50) Contact_No varchar(50) Email varchar(MAX) Date date No_of_TicketsReq int Collected bit No_of_TicketsBought int Sample dataRegistration_no Name Department Contact_No Email Date No_of_TicketsReq1 dee edede dede ded 01/06/2010 2 null NULL2 john test ict 3423 234324 01/06/2010 10 NULL NULL3 dee3 efrwer ewrwe werw 01/06/2010 1 NULL NULL4 gj gj ghj hgj 01/06/2010 5 NULL NULLwanted outputwhen the running sum of no_of_ticketsreq reaches 250 i need all the records that make up that 250 by date order or by registration no
Sachin.Nand
2937 Posts
Posted - 2010-06-04 : 06:53:38
Just to give u an idea how it can be done.
declare @tbl as table(r_no int identity,ticketno int)insert into @tblselect 10 union allselect 23 union allselect 54 union allselect 45 union allselect 56select * from @tblselect t1.r_no,t1.ticketno,SUM(t2.ticketno) from @tbl t1cross join @tbl t2where t1.r_no>=t2.r_nogroup by t1.r_no,t1.ticketnohaving SUM(t2.ticketno)>100order by r_no