How to fix this issue in sql [Resolved]

Posted by Jayakumars under C# on 4/21/2016 | Points: 10 | Views : 1458 | Status : [Member] [MVP] | Replies : 1
Hi

How to implemented this query


Create Table Employee
(
EName varchar(20),
AmtType varchar(30),
Cash decimal(18,2),
AAmount decimal(18,2),
BAmount decimal(18,2),
CAmount decimal(18,2),
)

Insert into Employee values('John','Car Loan',100,0,0,0)
Insert into Employee values('John','Car Loan',0,100,0,0)
Insert into Employee values('John','Car Loan',0,0,100,0)
Insert into Employee values('John','Car Loan',0,0,0,100)


Insert into Employee values('Wesly','Car Loan',0,100,0,0)
Insert into Employee values('Wesly','Car Loan',0,0,100,0)
Insert into Employee values('Wesly','Car Loan',0,0,0,100)



Select * from Employee

--I need output this

--John Car Loan 100 200 200 100
--Wesly Car Loan 0 100 100 100

Mark as Answer if its helpful to you

Kumaraspcode2009@gmail.com



Responses

Posted by: Rajnilari2015 on: 4/21/2016 [Member] [Microsoft_MVP] [MVP] Platinum | Points: 50

Up
0
Down

Resolved
Here you go

Select 


EName
,AmtType
,Cash = CAST(Max(Cash) AS INT)
,AAmount = CAST(Max(AAmount) + Max(Cash) AS INT)
,BAmount = CAST(Max(BAmount) + Max(Cash) AS INT)
,CAmount = CAST(Max(CAmount) AS INT)
From Employee
Group By EName,AmtType


Result
-------


EName 	AmtType         Cash   AAmount 	BAmount CAmount 

John Car Loan 100 200 200 100
Wesly Car Loan 0 100 100 100


--
Thanks & Regards,
RNA Team

Jayakumars, if this helps please login to Mark As Answer. | Alert Moderator

Login to post response