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.
| Author |
Topic |
|
sara_23apr
Starting Member
8 Posts |
Posted - 2008-03-17 : 20:46:03
|
| Hello friends , I have table (MoneyTrans) with following structure[Id] [bigint] NOT NULL,[TransDate] [smalldatetime] NOT NULL,[TransName] [varchar](30) NOT NULL, -- CAN have values 'Deposit' / 'WithDraw'[Amount] [money] NOT NULL I need to write a query to generate following output <br>Trans Date, total deposits, total withdrawls, closing balance <br>i.e. Trans Date, sum(amount) for TransName='Deposit' and Date=TransDate , sum(amount) for TransName=Withdraw and Date=TransDate , Closing balance (Sum of deposit - sum of withdraw for date < = TransDate )I am working on this for past two days with out getting a right solution. Any help is appreciatedSara |
|
|
QAZAFI
Yak Posting Veteran
50 Posts |
Posted - 2008-03-17 : 23:17:12
|
| SELECT TransDate, ISNULL(SUM( CASE WHEN TransName='deposit' then Amount end ),0) as DepositSum, ISNULL(SUM( CASE WHEN TransName='Withdraw' then Amount END ),0) as WithdrawSum, ISNULL(SUM( CASE WHEN TransName='deposit' then Amount end ),0)-ISNULL(SUM( CASE WHEN TransName='Withdraw' then Amount END ),0) as WithdrawSum from dbo.DepositWithdrawgroup by TransDate |
 |
|
|
sara_23apr
Starting Member
8 Posts |
Posted - 2008-03-18 : 00:52:33
|
| Hi QAZAFIThanks for the replyThis is your first post right!!.... so ur first post it self is an answer ! wow! inspiringThank you very muchSara |
 |
|
|
|
|
|
|
|