TECHNOLOGIES
FORUMS
JOBS
BOOKS
EVENTS
INTERVIEWS
Live
MORE
LEARN
Training
CAREER
MEMBERS
VIDEOS
NEWS
BLOGS
Sign Up
Login
No unread comment.
View All Comments
No unread message.
View All Messages
No unread notification.
View All Notifications
Answers
Post
An Article
A Blog
A News
A Video
An EBook
An Interview Question
Ask Question
Forums
Monthly Leaders
Forum guidelines
Jes Sie
742
1.2k
280.4k
Get Previous Balance, Received, Withdrawal and End Bal in SQL SERVER
Jul 6 2020 1:34 AM
I am trying to create a budgetting system for my company. The requirements from accounting states that I should get the previous balance then add it to the received amount. Subtract the sum of prev balance and received amount from the withdrawals to get the Balance end. Below is my stored procedure:
ALTER
PROCEDURE
[dbo].[fin_cash_flow_summary_LAK]
--'2020-07-06', '2020-07-06'
-- Add the parameters for the stored procedure here
@DateStart nvarchar(50),
@DateEnd nvarchar(50)
AS
BEGIN
-- SET NOCOUNT ON added to prevent extra result sets from
-- interfering with SELECT statements.
SET
NOCOUNT
ON
;
-- Insert statements for procedure here
SELECT
a.BankCode,
a.BankAcctType,
a.BankInformation,
a.CurrencyType,
(
SELECT
SUM
(
ISNULL
(b.CreditKip,0) -
ISNULL
(b.DebitKip,0))
FROM
fin_Cash_Flow_Master b
WHERE
a.BankInformation = b.BankInformation
AND
a.CurrencyType=
'LAK'
AND
a.BankAcctType <>
'Fixed'
AND
b.TransactionDate < @DateStart
)
AS
PreviousBalance,
SUM
(CreditKip)
AS
[Receive],
SUM
(DebitKip)
AS
Withdraw,
(
SELECT
SUM
(
ISNULL
(CreditKip, 0) -
ISNULL
(DebitKip, 0))
FROM
dbo.fin_Cash_Flow_Master
AS
b
WHERE
(a.BankInformation = BankInformation)
AND
(a.CurrencyType =
'LAK'
)
AND
(a.BankAcctType <>
'Fixed'
)
AND
(TransactionDate < @DateStart)) +
SUM
(CreditKip) -
SUM
(DebitKip)
AS
BalanceEnd
FROM
dbo.fin_Cash_Flow_Master a
WHERE
a.TransactionDate
BETWEEN
@DateStart
AND
@DateEnd
AND
a.CurrencyType =
'LAK'
AND
a.BankAcctType <>
'Fixed'
GROUP
BY
BankCode, BankAcctType, BankInformation, CurrencyType, BankAccountNo
END
With that query, I get results for previous balance before the start date if there is transaction on the date provided. But When I query it to the current day, I got nothing. Supposed to be, I am getting the previous balance. But, there is nothing to show. Please advice. Thank you so much
Reply
Answers (
3
)
how to program an Image class...?
How to convert Byte array of Image into .docx file?