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.

 All Forums
 SQL Server 2005 Forums
 Transact-SQL (2005)
 Need help in Sum clause

Author  Topic 

kamii47
Constraint Violating Yak Guru

353 Posts

Posted - 2008-08-27 : 03:52:05
here is the script to create the environment

create table tblTransaction(
intTransactionId int identity(1,1),
fltTransactionAmount float,
dtTransactionDate smalldatetime)
--drop table tblTransaction

insert into tblTransaction (fltTransactionAmount,dtTransactionDate) values(100,'2008-08-27')
insert into tblTransaction (fltTransactionAmount,dtTransactionDate) values(125,'2008-08-26')
insert into tblTransaction (fltTransactionAmount,dtTransactionDate) values(250,'2008-08-25')
insert into tblTransaction (fltTransactionAmount,dtTransactionDate) values(500,'2008-08-24')
insert into tblTransaction (fltTransactionAmount,dtTransactionDate) values(300,'2008-08-23')

select * from tblTransaction



Help me to find out the rows Surprise using SQL statement(no proc/func/cursor) or Is it possible to get the rows by sql statement ?

BTW i'm using sql server 2000.


-------------------sample input and expected output -------------------

input=800
output:
4 500.0 2008-08-24 00:00:00
5 300.0 2008-08-23 00:00:00

input=350.0
output:
1 100.0 2008-08-27 00:00:00
3 250.0 2008-08-25 00:00:00

input=300.0
output:
5 300.0 2008-08-23 00:00:00

input=100
output:
1 100.0 2008-08-27 00:00:00

Kamran Shahid
Sr. Software Engineer(MCSD.Net,MCPD.net)
www.netprosys.com

khtan
In (Som, Ni, Yak)

17689 Posts

Posted - 2008-08-27 : 04:00:40
see http://www.sqlteam.com/forums/topic.asp?TOPIC_ID=80857


KH
[spoiler]Time is always against us[/spoiler]

Go to Top of Page

kamii47
Constraint Violating Yak Guru

353 Posts

Posted - 2008-08-27 : 04:19:05
Sorry But to complex to understand.I needed it in a single query.[no variable]

Kamran Shahid
Sr. Software Engineer(MCSD.Net,MCPD.net)
www.netprosys.com
Go to Top of Page

khtan
In (Som, Ni, Yak)

17689 Posts

Posted - 2008-08-27 : 04:22:29
quote:
Originally posted by kamii47

Sorry But to complex to understand

Kamran Shahid
Sr. Software Engineer(MCSD.Net,MCPD.net)
www.netprosys.com




Yes I agree. It is indeed complex. If you want to try that solution, give it a try


KH
[spoiler]Time is always against us[/spoiler]

Go to Top of Page
   

- Advertisement -