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
Joginder Banger
214
8.7k
1m
Get Credit number
Feb 20 2017 8:24 AM
create
table
#CR(id
int
,
name
varchar
(
max
),CreditValue
int
,CreditDate datetime)
create
table
#DR(id
int
,
name
varchar
(
max
),debitValue
int
,CreditDate datetime)
INSERT
into
#CR
VALUES
(1,
'Jogi'
,5000,GETDATE())
INSERT
into
#CR
VALUES
(1,
'Jogi'
,7000,GETDATE())
INSERT
into
#CR
VALUES
(1,
'Jogi'
,9000,GETDATE())
insert
INTO
#DR
VALUES
(1,
'Jogi'
,3000,GETDATE())
insert
INTO
#DR
VALUES
(1,
'Jogi'
,4000,GETDATE())
insert
INTO
#DR
VALUES
(1,
'Jogi'
,7000,GETDATE())
;WITH Debit(Name,ID,TotalSum) AS
(
select Name,ID,sum(debitValue) from #DR1 GROUP by id,Name
),
Credit(Name,ID,TotalSum) AS
(
select Name,ID,sum(CreditValue) from #CR1 GROUP by id,Name
)
select Debit.Name,Credit.TotalSum as CR,Debit.TotalSum as DR,(Credit.TotalSum-Debit.TotalSum) Balance FROM Debit
inner join Credit on Debit.Id=Credit.ID
Reply
Answers (
1
)
Select Non Zero Multiple Columns From Select Statement
Need query for this Output