If this is your first visit, be sure to check out the FAQ by clicking the link above. You may have to register before you can post: click the register link above to proceed. To start viewing messages, select the forum that you want to visit from the selection below.

 
Go Back  dBforums > General > Database Concepts & Design > help in a query

Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1 (permalink)  
Old 09-18-10, 04:45
albloshi albloshi is offline
Registered User
 
Join Date: Sep 2010
Posts: 1
Red face help in a query

Good day all....
I av a problem in writing a query

I av two tables

Banks
-BankCode
-BankName
-BankBalance
-LastModified

BankTransaction
-StanNo
-VoucherNo
-BankCode
-ChequeNo
-Amount
-DebitCreditCheck
-Date
-Remarks
-AmountAfterTransaction

Whenever there is a debit/credit transaction from bank..it is recorded in bankTransaction table and BankBalance is updated in banks table...

I want to have ALL BANKS CREDITs on a specific date

My query is
(SELECT bTr.BankCode,SUM(CONVERT(money,bTr.Amount)) FROM benkTransaction bTr WHERE
bTr.DebitCreditCheck='CREDIT' AND bTr.[Date]<='7/16/2010' GROUP BY bTr.BankCode);

The problem is that If there is no transaction happened on or before this date ..there is no result.... I want it to be 0.00 if no transaction ever happened ...and the balance if some transaction happened before this period

I anticipate your quick response
Reply With Quote
  #2 (permalink)  
Old 09-20-10, 08:56
blindman blindman is offline
World Class Flame Warrior
 
Join Date: Jun 2003
Location: Ohio
Posts: 11,726
Here is your code*

Code:
SELECT	Banks.BankCode,
	SUM(CONVERT(money,BankTransaction.Amount))
FROM	Banks
	left outer join BankTransaction
		on Banks.BankCode = BankTransaction.BankCode
		and BankTransaction.DebitCreditCheck='CREDIT'
		and BankTransaction.[Date]<='7/16/2010'
GROUP BY Banks.BankCode



*Typos corrected and superfluous obfuscating table aliases removed.
__________________
If it's not practically useful, then it's practically useless.

blindman
www.chess.com: "sqlblindman"
Reply With Quote
Reply

Tags
database, query, query groups, sql 2008

Thread Tools Search this Thread
Search this Thread:

Advanced Search
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

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On