Click here to Skip to main content
15,894,646 members
Please Sign up or sign in to vote.
3.00/5 (1 vote)
See more:
Dear sir,

Here is the example:
Employeeid processmonth deductioncode Amount
100 02/22/2012 D[13] 150
100 02/22/2012 D[14] 200

I need in a single row as below:

Employeeid processmonth LoanAdvance MandatoryPF
100 02/22/2012 150 200


Note:
D[13] as a LoanAdvance

D[14] as a MandatoryPF


Thanks,
Please help me
Posted

Please try this

WITH employeeCTE AS
(SELECT Employeeid,processmonth,
CASE deductioncode
WHEN 'D[13]' THEN Amount END AS LoanAdvance ,
CASE deductioncode
WHEN 'D[14]' THEN Amount END AS MandatoryPF
FROM Employee)

SELECT Employeeid,processmonth,MAX(LoanAdvance) AS LoanAdvance,MAX(MandatoryPF)AS MandatoryPF
FROM employeeCTE
GROUP BY Employeeid,processmonth

Let me know the result..!!!
 
Share this answer
 
v2
Try This

SQL
select a.Employeeid a.processmonth a.Amount "LoanAdvance" a.Amount "MandatoryPF"
from Employee a, Employee b
where
a.Employeeid=b.Employeeid
and
a.deductioncode = 'D[13]'
and
b.deductioncode = 'D[14]'



And tell us what u r getting.
 
Share this answer
 
Comments
stanly jeba singh 22-Feb-12 4:45am    
i do not get any result for that query, but get the header's Like Employeeid,Processmonth,LoanAdvance,MandatoryPf
Hi,
SQL
SELECT *   FROM Employee
pivot(avg(Amount) for deductioncode in([LoanAdvance],[MandatoryPF]))as aaaa


Try this it works fine for me.
give me reply
Best Luck
 
Share this answer
 
v2
Comments
CGN007 22-Feb-12 5:33am    
The above query results LoanAdvance & MandatoryPF filled with Nulls
Nilesh Patil Kolhapur 22-Feb-12 6:13am    
impossible
CGN007 22-Feb-12 6:16am    
Fill the table
Employeeid processmonth deductioncode Amount
100 02/22/2012 D[13] 150
100 02/22/2012 D[14] 200


And try...!!!
Nilesh Patil Kolhapur 22-Feb-12 6:23am    
wait
Nilesh Patil Kolhapur 22-Feb-12 6:36am    
SELECT * FROM Employee
pivot(avg(Amount) for deductioncode in(D13,D14))as aaaa
try this and remove [] from your deductioncode values
Hi,
Finally Done
try this
SQL
SELECT Employeeid,processmonth,D13 as LoanAdvance, D14 as MandatoryPF
from (SELECT Employeeid, processmonth, deductioncode,Amount
FROM temp1) p
Pivot(avg (Amount) for deductioncode in(D13,D14))as aaaa

I learned lot from this Question.
Thanks.

*Note- Dont use [] ok

Good Luck
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900